// quadtrees.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "quadtrees.h"
#include<string.h>

#define MAX_LOADSTRING 100
#define RADACINA 0
#define RADsi4F 1
#define NW_H 2
#define NE_H 3
#define SW_H 4
#define SE_H 5
#define NW_NW 6
#define NW_NE 7
#define NW_SW 8
#define NW_SE 9
#define NE_NW 10
#define NE_NE 11
#define NE_SW 12
#define NE_SE 13
#define SW_NW 14
#define SW_NE 15
#define SW_SW 16
#define SW_SE 17
#define SE_NW 18
#define SE_NE 19
#define SE_SW 20
#define SE_SE 21


// Global Variables:
HINSTANCE hInst;								// current instance
TCHAR szTitle[MAX_LOADSTRING];					// The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];			// the main window class name
HWND Dialog=NULL;
HWND Dialog2=NULL;
HWND Dialog3=NULL;
HWND hWnd2,hWnd3,hWnd4;
int R,G,B,left,top,right,bottom,ok=0,grid=0,initt=0;
int col,aux,aux2,aux3,aux4;
RECT *r,*r2;
char indexnod[10];

typedef struct nod
{char index[10];
 int culoare;
 nod *NW,*NE,*SW,*SE;
} nod;
nod *head;
typedef struct culoare
{int R,G,B;}
culoare;
culoare c[10];
typedef struct pixel
{int index;
 int culoare;
 int left,right,top,bottom;
}pixel;
 pixel p[65];
 void init_culori()
 {c[1].R=0;c[1].G=0;;c[1].B=0;
  c[2].R=255;c[2].G=0;c[2].B=0;
  c[3].R=0;c[3].G=255;c[3].B=0;
  c[4].R=0;c[4].G=0;c[4].B=255;
  c[5].R=255;c[5].G=255;c[5].B=0;
  c[6].R=255;c[6].G=0;c[6].B=255;
  c[7].R=0;c[7].G=255;c[7].B=255;
  c[8].R=255;c[8].G=255;c[8].B=255;
  c[9].R=128;c[9].G=128;c[9].B=128;}
 void init()
 {int i,j,x=1000,y=25;
  int index=1;
  for(i=0;i<8;i++)
	  for(j=0;j<8;j++)
		{p[index].index=index;
		 p[index].culoare=8;
		 p[index].left=x+25*j;
		 p[index].top=y+25*i;
		 p[index].right=p[index].left+25;
		 p[index].bottom=p[index].top+25;
		 if(j!=3)
		 if(j%2==0)
			 index++;
			else
			 index=index+3;
		 if(j==3)
			 index=index+11;
		 if(j==7)
			switch(i) {	case 0:index=3;break;
						case 1:index=9;break;
						case 2:index=11;break;
						case 3:index=33;break;
						case 4:index=35;break;
						case 5:index=41;break;
						case 6:index=43;break;
					  }
		}	
 }
 

// Forward declarations of functions included in this code module:
ATOM				MyRegisterClass(HINSTANCE hInstance);
BOOL				InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK	About(HWND, UINT, WPARAM, LPARAM);
#pragma argsused

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);
	init();
	init_culori();
 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;

	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_QUADTREES, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_QUADTREES));

	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0))
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return (int) msg.wParam;
}



//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
//    This function and its usage are only necessary if you want this code
//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get 'well formed' small icons associated
//    with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX);

	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_QUADTREES));
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= MAKEINTRESOURCE(IDC_QUADTREES);
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

	return RegisterClassEx(&wcex);
}

//
//   FUNCTION: InitInstance(HINSTANCE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   

   hInst = hInstance; // Store instance handle in our global variable

   hWnd2 = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, CW_USEDEFAULT,2000,750, NULL, NULL, hInstance, NULL);

   if (!hWnd2)
   {
      return FALSE;
   }

   ShowWindow(hWnd2, nCmdShow);
   UpdateWindow(hWnd2);

   return TRUE;
}

void colorare(HDC hdc,PAINTSTRUCT ps,int R,int G,int B,int left,int top,int right,int bottom)
 {if(R==255&G==255&B==255)
	  {Rectangle(hdc,left,top,right,bottom);
	   return;}
  HBRUSH currentbrush=CreateSolidBrush(RGB(R,G,B));
  r=(RECT*)malloc(sizeof(RECT));
  r->left=left;r->top=top;r->right=right;r->bottom=bottom;
  FillRect(hdc,r,currentbrush);
  free(r);
 }

void patrat(int col,int left,int top,int right,int bottom)
{r=(RECT*)malloc(sizeof(RECT));
 r->left=left;r->top=top;r->right=right;r->bottom=bottom;
 R=c[col].R;G=c[col].G;B=c[col].B;
}

void colorare_arbore();
void depthfirst(nod *root);
BOOL CALLBACK DialogProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{switch(msg){
	case WM_INITDIALOG: return TRUE;
	case WM_COMMAND:{
		switch(wParam){
			case IDC_negru:col=1;break;
			case IDC_rosu:col=2;break;
			case IDC_verde:col=3;break;
			case IDC_albastru:col=4;break;
			case IDC_galben:col=5;break;
			case IDC_violet:col=6;break;
			case IDC_bleumarin:col=7;break;
			case IDC_alb:col=8;break;
			case IDC_BUTTON01:{if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[1].culoare=col;
							   left=p[1].left;top=p[1].top;right=p[1].right;bottom=p[1].bottom;
							   ok=1;
							   patrat(col,p[1].left,p[1].top,p[1].right,p[1].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							  }
						break;
			case IDC_BUTTON02: {
				                if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[2].culoare=col;
							   left=p[2].left;top=p[2].top;right=p[2].right;bottom=p[2].bottom;
							   ok=1;
							   patrat(col,p[2].left,p[2].top,p[2].right,p[2].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break;
			case IDC_BUTTON03: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[3].culoare=col;
							   left=p[3].left;top=p[3].top;right=p[3].right;bottom=p[3].bottom;
							   ok=1;
							   patrat(col,p[3].left,p[3].top,p[3].right,p[3].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break;
			case IDC_BUTTON04: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[4].culoare=col;
							   left=p[4].left;top=p[4].top;right=p[4].right;bottom=p[4].bottom;
							   ok=1;
							   patrat(col,p[4].left,p[4].top,p[4].right,p[4].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break;
			case IDC_BUTTON05: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[5].culoare=col;
							   left=p[5].left;top=p[5].top;right=p[5].right;bottom=p[5].bottom;
							   ok=1;
							   patrat(col,p[5].left,p[5].top,p[5].right,p[5].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break;
			case IDC_BUTTON06: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[6].culoare=col;
							   left=p[6].left;top=p[6].top;right=p[6].right;bottom=p[6].bottom;
							   ok=1;
							   patrat(col,p[6].left,p[6].top,p[6].right,p[6].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break;
			case IDC_BUTTON07: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[7].culoare=col;
							   left=p[7].left;top=p[7].top;right=p[7].right;bottom=p[7].bottom;
							   ok=1;
							   patrat(col,p[7].left,p[7].top,p[7].right,p[7].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break;
			case IDC_BUTTON08: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[8].culoare=col;
							   left=p[8].left;top=p[8].top;right=p[8].right;bottom=p[8].bottom;
							   ok=1;
							   patrat(col,p[8].left,p[8].top,p[8].right,p[8].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break;
			case IDC_BUTTON09: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[9].culoare=col;
							   left=p[9].left;top=p[9].top;right=p[9].right;bottom=p[9].bottom;
							   ok=1;
							   patrat(col,p[9].left,p[9].top,p[9].right,p[9].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break;
			case IDC_BUTTON10: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[10].culoare=col;
							   left=p[10].left;top=p[10].top;right=p[10].right;bottom=p[10].bottom;
							   ok=1;
							   patrat(col,p[10].left,p[10].top,p[10].right,p[10].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break;
			case IDC_BUTTON11: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[11].culoare=col;
							   left=p[11].left;top=p[11].top;right=p[11].right;bottom=p[11].bottom;
							   ok=1;
							   patrat(col,p[11].left,p[11].top,p[11].right,p[11].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break;
			case IDC_BUTTON12: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[12].culoare=col;
							   left=p[12].left;top=p[12].top;right=p[12].right;bottom=p[12].bottom;
							   ok=1;
							   patrat(col,p[12].left,p[12].top,p[12].right,p[12].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break;
			case IDC_BUTTON13: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[13].culoare=col;
							   left=p[13].left;top=p[13].top;right=p[13].right;bottom=p[13].bottom;
							   ok=1;
							   patrat(col,p[13].left,p[13].top,p[13].right,p[13].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break;
			case IDC_BUTTON14: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[14].culoare=col;
							   left=p[14].left;top=p[14].top;right=p[14].right;bottom=p[14].bottom;
							   ok=1;
							   patrat(col,p[14].left,p[14].top,p[14].right,p[14].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break;
			case IDC_BUTTON15: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[15].culoare=col;
							   left=p[15].left;top=p[15].top;right=p[15].right;bottom=p[15].bottom;
							   ok=1;
							   patrat(col,p[15].left,p[15].top,p[15].right,p[15].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break;
			case IDC_BUTTON16: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[16].culoare=col;
							   left=p[16].left;top=p[16].top;right=p[16].right;bottom=p[16].bottom;
							   ok=1;
							   patrat(col,p[16].left,p[16].top,p[16].right,p[16].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON17: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[17].culoare=col;
							   left=p[17].left;top=p[17].top;right=p[17].right;bottom=p[17].bottom;
							   ok=1;
							   patrat(col,p[17].left,p[17].top,p[17].right,p[17].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON18: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[18].culoare=col;
							   left=p[18].left;top=p[18].top;right=p[18].right;bottom=p[18].bottom;
							   ok=1;
							   patrat(col,p[18].left,p[18].top,p[18].right,p[18].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON19: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[19].culoare=col;
							   left=p[19].left;top=p[19].top;right=p[19].right;bottom=p[19].bottom;
							   ok=1;
							   patrat(col,p[19].left,p[19].top,p[19].right,p[19].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON20: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[20].culoare=col;
							   left=p[20].left;top=p[20].top;right=p[20].right;bottom=p[20].bottom;
							   ok=1;
							   patrat(col,p[20].left,p[20].top,p[20].right,p[20].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON21: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[21].culoare=col;
							   left=p[21].left;top=p[21].top;right=p[21].right;bottom=p[21].bottom;
							   ok=1;
							   patrat(col,p[21].left,p[21].top,p[21].right,p[21].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON22: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[22].culoare=col;
							   left=p[22].left;top=p[22].top;right=p[22].right;bottom=p[22].bottom;
							   ok=1;
							   patrat(col,p[22].left,p[22].top,p[22].right,p[22].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON23: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[23].culoare=col;
							   left=p[23].left;top=p[23].top;right=p[23].right;bottom=p[23].bottom;
							   ok=1;
							   patrat(col,p[23].left,p[23].top,p[23].right,p[23].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON24: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[24].culoare=col;
							   left=p[24].left;top=p[24].top;right=p[24].right;bottom=p[24].bottom;
							   ok=1;
							   patrat(col,p[24].left,p[24].top,p[24].right,p[24].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON25: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[25].culoare=col;
							   left=p[25].left;top=p[25].top;right=p[25].right;bottom=p[25].bottom;
							   ok=1;
							   patrat(col,p[25].left,p[25].top,p[25].right,p[25].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break;
			case IDC_BUTTON26: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[26].culoare=col;
							   left=p[26].left;top=p[26].top;right=p[26].right;bottom=p[26].bottom;
							   ok=1;
							   patrat(col,p[26].left,p[26].top,p[26].right,p[26].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break;
			case IDC_BUTTON27: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[27].culoare=col;
							   left=p[27].left;top=p[27].top;right=p[27].right;bottom=p[27].bottom;
							   ok=1;
							   patrat(col,p[27].left,p[27].top,p[27].right,p[27].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON28: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[28].culoare=col;
							   left=p[28].left;top=p[28].top;right=p[28].right;bottom=p[28].bottom;
							   ok=1;
							   patrat(col,p[28].left,p[28].top,p[28].right,p[28].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON29: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[29].culoare=col;
							   left=p[29].left;top=p[29].top;right=p[29].right;bottom=p[29].bottom;
							   ok=1;
							   patrat(col,p[29].left,p[29].top,p[29].right,p[29].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON30: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[30].culoare=col;
							   left=p[30].left;top=p[30].top;right=p[30].right;bottom=p[30].bottom;
							   ok=1;
							   patrat(col,p[30].left,p[30].top,p[30].right,p[30].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON31: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[31].culoare=col;
							   left=p[31].left;top=p[31].top;right=p[31].right;bottom=p[31].bottom;
							   ok=1;
							   patrat(col,p[31].left,p[31].top,p[31].right,p[31].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON32: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[32].culoare=col;
							   left=p[32].left;top=p[32].top;right=p[32].right;bottom=p[32].bottom;
							   ok=1;
							   patrat(col,p[32].left,p[32].top,p[32].right,p[32].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON33: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[33].culoare=col;
							   left=p[33].left;top=p[33].top;right=p[33].right;bottom=p[33].bottom;
							   ok=1;
							   patrat(col,p[33].left,p[33].top,p[33].right,p[33].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON34: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[34].culoare=col;
							   left=p[34].left;top=p[34].top;right=p[34].right;bottom=p[34].bottom;
							   ok=1;
							   patrat(col,p[34].left,p[34].top,p[34].right,p[34].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON35: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[35].culoare=col;
							   left=p[35].left;top=p[35].top;right=p[35].right;bottom=p[35].bottom;
							   ok=1;
							   patrat(col,p[35].left,p[35].top,p[35].right,p[35].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON36: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[36].culoare=col;
							   left=p[36].left;top=p[36].top;right=p[36].right;bottom=p[36].bottom;
							   ok=1;
							   patrat(col,p[36].left,p[36].top,p[36].right,p[36].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON37: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[37].culoare=col;
							   left=p[37].left;top=p[37].top;right=p[37].right;bottom=p[37].bottom;
							   ok=1;
							   patrat(col,p[37].left,p[37].top,p[37].right,p[37].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON38: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[38].culoare=col;
							   left=p[38].left;top=p[38].top;right=p[38].right;bottom=p[38].bottom;
							   ok=1;
							   patrat(col,p[38].left,p[38].top,p[38].right,p[38].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON39: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[39].culoare=col;
							   left=p[39].left;top=p[39].top;right=p[39].right;bottom=p[39].bottom;
							   ok=1;
							   patrat(col,p[39].left,p[39].top,p[39].right,p[39].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON40: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[40].culoare=col;
							   left=p[40].left;top=p[40].top;right=p[40].right;bottom=p[40].bottom;
							   ok=1;
							   patrat(col,p[40].left,p[40].top,p[40].right,p[40].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON41: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[41].culoare=col;
							   left=p[41].left;top=p[41].top;right=p[41].right;bottom=p[41].bottom;
							   ok=1;
							   patrat(col,p[41].left,p[41].top,p[41].right,p[41].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON42: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[42].culoare=col;
							   left=p[42].left;top=p[42].top;right=p[42].right;bottom=p[42].bottom;
							   ok=1;
							   patrat(col,p[42].left,p[42].top,p[42].right,p[42].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON43: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[43].culoare=col;
							   left=p[43].left;top=p[43].top;right=p[43].right;bottom=p[43].bottom;
							   ok=1;
							   patrat(col,p[43].left,p[43].top,p[43].right,p[43].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break;
			case IDC_BUTTON44: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[44].culoare=col;
							   left=p[44].left;top=p[44].top;right=p[44].right;bottom=p[44].bottom;
							   ok=1;
							   patrat(col,p[44].left,p[44].top,p[44].right,p[44].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break;
			case IDC_BUTTON45: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[45].culoare=col;
							   left=p[45].left;top=p[45].top;right=p[45].right;bottom=p[45].bottom;
							   ok=1;
							   patrat(col,p[45].left,p[45].top,p[45].right,p[45].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break;
			case IDC_BUTTON46: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[46].culoare=col;
							   left=p[46].left;top=p[46].top;right=p[46].right;bottom=p[46].bottom;
							   ok=1;
							   patrat(col,p[46].left,p[46].top,p[46].right,p[46].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON47: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[47].culoare=col;
							   left=p[47].left;top=p[47].top;right=p[47].right;bottom=p[47].bottom;
							   ok=1;
							   patrat(col,p[47].left,p[47].top,p[47].right,p[47].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break;
			case IDC_BUTTON48: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[48].culoare=col;
							   left=p[48].left;top=p[48].top;right=p[48].right;bottom=p[48].bottom;
							   ok=1;
							   patrat(col,p[48].left,p[48].top,p[48].right,p[48].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON49: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[49].culoare=col;
							   left=p[49].left;top=p[49].top;right=p[49].right;bottom=p[49].bottom;
							   ok=1;
							   patrat(col,p[49].left,p[49].top,p[49].right,p[49].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON50: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[50].culoare=col;
							   left=p[50].left;top=p[50].top;right=p[50].right;bottom=p[50].bottom;
							   ok=1;
							   patrat(col,p[50].left,p[50].top,p[50].right,p[50].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON51: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[51].culoare=col;
							   left=p[51].left;top=p[51].top;right=p[51].right;bottom=p[51].bottom;
							   ok=1;
							   patrat(col,p[51].left,p[51].top,p[51].right,p[51].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON52: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[52].culoare=col;
							   left=p[52].left;top=p[52].top;right=p[52].right;bottom=p[52].bottom;
							   ok=1;
							   patrat(col,p[52].left,p[52].top,p[52].right,p[52].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON53: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[53].culoare=col;
							   left=p[53].left;top=p[53].top;right=p[53].right;bottom=p[53].bottom;
							   ok=1;
							   patrat(col,p[53].left,p[53].top,p[53].right,p[53].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break;
			case IDC_BUTTON54: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[54].culoare=col;
							   left=p[54].left;top=p[54].top;right=p[54].right;bottom=p[54].bottom;
							   ok=1;
							   patrat(col,p[54].left,p[54].top,p[54].right,p[54].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
		    case IDC_BUTTON55: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[55].culoare=col;
							   left=p[55].left;top=p[55].top;right=p[55].right;bottom=p[55].bottom;
							   ok=1;
							   patrat(col,p[55].left,p[55].top,p[55].right,p[55].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON56: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[56].culoare=col;
							   left=p[56].left;top=p[56].top;right=p[56].right;bottom=p[56].bottom;
							   ok=1;
							   patrat(col,p[56].left,p[56].top,p[56].right,p[56].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON57: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[57].culoare=col;
							   left=p[57].left;top=p[57].top;right=p[57].right;bottom=p[57].bottom;
							   ok=1;
							   patrat(col,p[57].left,p[57].top,p[57].right,p[57].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON58: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[58].culoare=col;
							   left=p[58].left;top=p[58].top;right=p[58].right;bottom=p[58].bottom;
							   ok=1;
							   patrat(col,p[58].left,p[58].top,p[58].right,p[58].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON59: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[59].culoare=col;
							   left=p[59].left;top=p[59].top;right=p[59].right;bottom=p[59].bottom;
							   ok=1;
							   patrat(col,p[59].left,p[59].top,p[59].right,p[59].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON60: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[60].culoare=col;
							   left=p[60].left;top=p[60].top;right=p[60].right;bottom=p[60].bottom;
							   ok=1;
							   patrat(col,p[60].left,p[60].top,p[60].right,p[60].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break;
			case IDC_BUTTON61: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[61].culoare=col;
							   left=p[61].left;top=p[61].top;right=p[61].right;bottom=p[61].bottom;
							   ok=1;
							   patrat(col,p[61].left,p[61].top,p[61].right,p[61].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON62: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[62].culoare=col;
							   left=p[62].left;top=p[62].top;right=p[62].right;bottom=p[62].bottom;
							   ok=1;
							   patrat(col,p[62].left,p[62].top,p[62].right,p[62].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break;
			case IDC_BUTTON63: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[63].culoare=col;
							   left=p[63].left;top=p[63].top;right=p[63].right;bottom=p[63].bottom;
							   ok=1;
							   patrat(col,p[63].left,p[63].top,p[63].right,p[63].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON64: {if(col==0)
									{MessageBox(hWnd2,"Nu ati selectat culoarea dorita","Eroare",NULL);break;}
							   p[64].culoare=col;
							   left=p[64].left;top=p[64].top;right=p[64].right;bottom=p[64].bottom;
							   ok=1;
							   patrat(col,p[64].left,p[64].top,p[64].right,p[64].bottom);
							   InvalidateRect(hWnd2,r,FALSE);
							   free(r);
							   EndDialog(Dialog,0);
							   }
						break; 
			case IDC_BUTTON65:ok=2;
							  EndDialog(Dialog,1);
							  r=(RECT*)malloc(sizeof(RECT));
							  r->left=0;r->top=250;r->right=1500;r->bottom=750;
							  InvalidateRect(hWnd2,r,FALSE);
						break;
							}
						break;
					}
	case WM_CLOSE:
		EndDialog(Dialog,0);
        break;  
	default: return FALSE;
			}
 return TRUE;
}
void colorare_arbore()
{int i,col,caz=RADACINA;
 col=p[1].culoare;
 for(i=2;i<=64;i++)
	 if(col!=p[i].culoare)
		 {caz=RADsi4F;
		  break;
		 }
 //cazul RADACINA
 head=(nod*)malloc(sizeof(nod));
 strcpy(head->index,"ROOT");
 head->NW=head->NE=head->SW=head->SE=0;
 if(caz==RADACINA)
	 {if(col==8)
		 {MessageBox(hWnd2,"Nu a fost colorat niciun patrat!","Eroare",NULL);
		  Dialog=CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_PROPPAGE_LARGE), hWnd2,reinterpret_cast<DLGPROC>(DialogProc));
		  if(Dialog==NULL)
				MessageBox(hWnd2,"eroare dialog","eroare",NULL);
		  ShowWindow(Dialog,SW_SHOW);
		 }		
	   head->culoare=col;
	   return;
	  }
 //sunt in cazul RADsi4F
 if(caz==RADsi4F)
		{col=p[1].culoare;
		 head->culoare=9;
		 //////cazul NW/////////
		 for(i=2;i<=16;i++)
			 if(p[i].culoare!=col)
				{caz=NW_H;break;}
		 nod *NW=(nod*)malloc(sizeof(nod));
	     strcpy(NW->index,"NW_H");
		 NW->NW=NW->NE=NW->SW=NW->SE=0;
		 head->NW=NW;
		 if(caz!=NW_H)
			 NW->culoare=col;
		   else
			 {NW->culoare=9;
			  col=p[1].culoare;
			  for(i=2;i<=4;i++)
				  if(col!=p[i].culoare)
					  caz=NW_NW;//cazult NW_NW////////////
			  nod *NW1=(nod*)malloc(sizeof(nod));
			  strcpy(NW1->index,"NW_NW");
			  NW->NW=NW1;
			  NW1->NW=NW1->NE=NW1->SW=NW1->SE=0;
			  if(caz!=NW_NW)
				  NW1->culoare=col;
				else
				 {NW1->culoare=9;
				  for(i=1;i<=4;i++)
					{char aux[3];
					 switch(i){case 1:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NW1->NW=crt;
									  break;}
							   case 2:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NW1->NE=crt;break;}
							   case 3:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NW1->SW=crt;break;}
							   case 4:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NW1->SE=crt;break;}
							  }
					}
			     }
			 
			  col=p[5].culoare;
			  for(i=6;i<=8;i++)
				  if(col!=p[i].culoare)
					  caz=NW_NE;//cazul NW_NE//////////
			  nod *NE1=(nod*)malloc(sizeof(nod));
			  strcpy(NE1->index,"NW_NE");
			  NW->NE=NE1;
			  NE1->NW=NE1->NE=NE1->SW=NE1->SE=0;
			  if(caz!=NW_NE)
				  NE1->culoare=col;
				else
				 {NE1->culoare=9;
				  nod *crt=(nod*)malloc(sizeof(nod));
				  for(i=5;i<=8;i++)
					{char aux[3];
					 switch(i){case 5:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NE1->NW=crt;
									  break;}
							   case 6:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NE1->NE=crt;break;}
							   case 7:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NE1->SW=crt;break;}
							   case 8:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NE1->SE=crt;break;}
							  }
				     }
			    }
			  col=p[9].culoare;
			  for(i=10;i<=12;i++)
				  if(col!=p[i].culoare)
					  caz=NW_SW;////cazul NW_SW////
			  nod *SW1=(nod*)malloc(sizeof(nod));
			  strcpy(SW1->index,"NW_SW");
			  NW->SW=SW1;
			  SW1->NW=SW1->NE=SW1->SW=SW1->SE=0;
			  if(caz!=NW_SW)
				  SW1->culoare=col;
				else
				 {SW1->culoare=9;
				  nod *crt=(nod*)malloc(sizeof(nod));
				  for(i=9;i<=12;i++)
					{char aux[3];
					 switch(i){case 9:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SW1->NW=crt;
									  break;}
							   case 10:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SW1->NE=crt;break;}
							   case 11:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SW1->SW=crt;break;}
							   case 12:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SW1->SE=crt;break;}
							  }
					}
			     }
			  col=p[13].culoare;
			  for(i=14;i<=16;i++)
				  if(col!=p[i].culoare)
					  caz=NW_SE;/////cazul NW_SE///////
			  nod *SE1=(nod*)malloc(sizeof(nod));
			  strcpy(SE1->index,"NW_SE");
			  NW->SE=SE1;
			  SE1->NW=SE1->NE=SE1->SW=SE1->SE=0;
			  if(caz!=NW_SE)
				  SE1->culoare=col;
				else
				 {SE1->culoare=9;
				  nod *crt=(nod*)malloc(sizeof(nod));
				  for(i=13;i<=16;i++)
					{char aux[3];
					 switch(i){case 13:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SE1->NW=crt;
									  break;}
							   case 14:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SE1->NE=crt;break;}
							   case 15:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SE1->SW=crt;break;}
							   case 16:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SE1->SE=crt;break;}
							  }
					}
				}
			  }
			  ///////cazul NE////////
		  col=p[17].culoare;
		  for(i=18;i<=32;i++)
			 if(p[i].culoare!=col)
				{caz=NE_H;break;}
		 nod *NE=(nod*)malloc(sizeof(nod));
	     strcpy(NE->index,"NE_H");
		 NE->NW=NE->NE=NE->SW=NE->SE=0;
		 head->NE=NE;
		 if(caz!=NE_H)
			 NE->culoare=col;
		   else
			 {NE->culoare=9;
			  col=p[17].culoare;
			  for(i=18;i<=20;i++)
				  if(col!=p[i].culoare)
					  caz=NE_NW;//cazult NE_NW////////////
			  nod *NW2=(nod*)malloc(sizeof(nod));
			  strcpy(NW2->index,"NE_NW");
			  NE->NW=NW2;
			  NW2->NW=NW2->NE=NW2->SW=NW2->SE=0;
			  if(caz!=NE_NW)
				  NW2->culoare=col;
				else
				 {NW2->culoare=9;
				  nod *crt=(nod*)malloc(sizeof(nod));
				  for(i=17;i<=20;i++)
					{char aux[3];
					 switch(i){case 17:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NW2->NW=crt;
									  break;}
							   case 18:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NW2->NE=crt;break;}
							   case 19:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NW2->SW=crt;break;}
							   case 20:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NW2->SE=crt;break;}
							  }
					}
				 }
			  col=p[21].culoare;
			  for(i=21;i<=24;i++)
				  if(col!=p[i].culoare)
					  caz=NE_NE;//cazul NE_NE//////////
			  nod *NE2=(nod*)malloc(sizeof(nod));
			  strcpy(NE2->index,"NE_NE");
			  NE->NE=NE2;
			  NE2->NW=NE2->NE=NE2->SW=NE2->SE=0;
			  if(caz!=NE_NE)
				  NE2->culoare=col;
				else
				 {NE2->culoare=9;
				  nod *crt=(nod*)malloc(sizeof(nod));
				  for(i=21;i<=24;i++)
					{char aux[3];
					 switch(i){case 21:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NE2->NW=crt;
									  break;}
							   case 22:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NE2->NE=crt;break;}
							   case 23:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NE2->SW=crt;break;}
							   case 24:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NE2->SE=crt;break;}
							  }
					}
			    }
			  col=p[25].culoare;
			  for(i=26;i<=28;i++)
				  if(col!=p[i].culoare)
					  caz=NE_SW;////cazul NE_SW////
			  nod *SW2=(nod*)malloc(sizeof(nod));
			  strcpy(SW2->index,"NE_SW");
			  NE->SW=SW2;
			  SW2->NW=SW2->NE=SW2->SW=SW2->SE=0;
			  if(caz!=NE_SW)
				  SW2->culoare=col;
				else
				 {SW2->culoare=9;
				  nod *crt=(nod*)malloc(sizeof(nod));
				  for(i=25;i<=28;i++)
					{char aux[3];
					 switch(i){case 25:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SW2->NW=crt;
									  break;}
							   case 26:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SW2->NE=crt;break;}
							   case 27:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SW2->SW=crt;break;}
							   case 28:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SW2->SE=crt;break;}
							  }
					}
			     }
			  col=p[29].culoare;
			  for(i=30;i<=32;i++)
				  if(col!=p[i].culoare)
					  caz=NE_SE;/////cazul NE_SE///////
			  nod *SE2=(nod*)malloc(sizeof(nod));
			  strcpy(SE2->index,"NE_SE");
			  NE->SE=SE2;
			  SE2->NW=SE2->NE=SE2->SW=SE2->SE=0;
			  if(caz!=NE_SE)
				  SE2->culoare=col;
				else
				 {SE2->culoare=9;
				  nod *crt=(nod*)malloc(sizeof(nod));
				  for(i=29;i<=32;i++)
					{char aux[3];
					 switch(i){case 29:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SE2->NW=crt;
									  break;}
							   case 30:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SE2->NE=crt;break;}
							   case 31:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SE2->SW=crt;break;}
							   case 32:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SE2->SE=crt;break;}
							  }
					}
			     }
		 }
		 //////cazul SW////////
		 col=p[33].culoare;
		 for(i=34;i<=48;i++)
			 if(p[i].culoare!=col)
				{caz=SW_H;break;}
		 nod *SW=(nod*)malloc(sizeof(nod));
	     strcpy(SW->index,"SW_H");
		 SW->NW=SW->NE=SW->SW=SW->SE=0;
		 head->SW=SW;
		 if(caz!=SW_H)
			 SW->culoare=col;
		   else
			 {SW->culoare=9;
			  col=p[33].culoare;
			  for(i=34;i<=36;i++)
				  if(col!=p[i].culoare)
					  caz=SW_NW;//cazult SW_NW////////////
			  nod *NW3=(nod*)malloc(sizeof(nod));
			  strcpy(NW3->index,"SW_NW");
			  SW->NW=NW3;
			  NW3->NW=NW3->NE=NW3->SW=NW3->SE=0;
			  if(caz!=SW_NW)
				  NW3->culoare=col;
				else
				 {NW3->culoare=9;
				  nod *crt=(nod*)malloc(sizeof(nod));
				  for(i=33;i<=36;i++)
					{char aux[3];
					 switch(i){case 33:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NW3->NW=crt;
									  break;}
							   case 34:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NW3->NE=crt;break;}
							   case 35:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NW3->SW=crt;break;}
							   case 36:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NW3->SE=crt;break;}
							  }
					}
			     }
			  col=p[37].culoare;
			  for(i=38;i<=40;i++)
				  if(col!=p[i].culoare)
					  caz=SW_NE;//cazul SW_NE//////////
			  nod *NE3=(nod*)malloc(sizeof(nod));
			  strcpy(NE3->index,"SW_NE");
			  SW->NE=NE3;
			  NE3->NW=NE3->NE=NE3->SW=NE3->SE=0;
			  if(caz!=SW_NE)
				  NE3->culoare=col;
				else
				 {NE3->culoare=9;
				  nod *crt=(nod*)malloc(sizeof(nod));
				  for(i=37;i<=40;i++)
					{char aux[3];
					 switch(i){case 37:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NE3->NW=crt;
									  break;}
							   case 38:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NE3->NE=crt;break;}
							   case 39:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NE3->SW=crt;break;}
							   case 40:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NE3->SE=crt;break;}
							  }
					}
			    }
			  col=p[41].culoare;
			  for(i=42;i<=44;i++)
				  if(col!=p[i].culoare)
					  caz=SW_SW;////cazul SW_SW////
			  nod *SW3=(nod*)malloc(sizeof(nod));
			  strcpy(SW3->index,"SW_SW");
			  SW->SW=SW3;
			  SW3->NW=SW3->NE=SW3->SW=SW3->SE=0;
			  if(caz!=SW_SW)
				  SW3->culoare=col;
				else
				 {SW3->culoare=9;
				  nod *crt=(nod*)malloc(sizeof(nod));
				  for(i=41;i<=44;i++)
					{char aux[3];
					 switch(i){case 41:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SW3->NW=crt;
									  break;}
							   case 42:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SW3->NE=crt;break;}
							   case 43:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SW3->SW=crt;break;}
							   case 44:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SW3->SE=crt;break;}
							  }
					}
			     }
			  col=p[45].culoare;
			  for(i=46;i<=48;i++)
				  if(col!=p[i].culoare)
					  caz=SW_SE;/////cazul SW_SE///////
			  nod *SE3=(nod*)malloc(sizeof(nod));
			  strcpy(SE3->index,"SW_SE");
			  SW->SE=SE3;
			  SE3->NW=SE3->NE=SE3->SW=SE3->SE=0;
			  if(caz!=SW_SE)
				  SE3->culoare=col;
				else
				 {SE3->culoare=9;
				  nod *crt=(nod*)malloc(sizeof(nod));
				  for(i=45;i<=48;i++)
					{char aux[3];
					 switch(i){case 45:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SE3->NW=crt;
									  break;}
							   case 46:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SE3->NE=crt;break;}
							   case 47:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SE3->SW=crt;break;}
							   case 48:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SE3->SE=crt;break;}
							  }
					}
			     }
		 }
		 ////////cazul SE///////////
		 col=p[49].culoare;
		 for(i=50;i<=64;i++)
			 if(p[i].culoare!=col)
				{caz=SE_H;break;}
		 nod *SE=(nod*)malloc(sizeof(nod));
	     strcpy(SE->index,"SE_H");
		 SE->NW=SE->NE=SE->SW=SE->SE=0;
		 head->SE=SE;
		 if(caz!=SE_H)
			 SE->culoare=col;
		   else
			 {SE->culoare=9;
			  col=p[49].culoare;
			  for(i=50;i<=52;i++)
				  if(col!=p[i].culoare)
					  caz=SE_NW;//cazult SE_NW////////////
			  nod *NW4=(nod*)malloc(sizeof(nod));
			  strcpy(NW4->index,"SE_NW");
			  SE->NW=NW4;
			  NW4->NW=NW4->NE=NW4->SW=NW4->SE=0;
			  if(caz!=SE_NW)
				  NW4->culoare=col;
				else
				 {NW4->culoare=9;
				  nod *crt=(nod*)malloc(sizeof(nod));
				  for(i=49;i<=52;i++)
					{char aux[3];
					 switch(i){case 49:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NW4->NW=crt;
									  break;}
							   case 50:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NW4->NE=crt;break;}
							   case 51:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NW4->SW=crt;break;}
							   case 52:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NW4->SE=crt;break;}
							  }
					}
			     }
			  col=p[53].culoare;
			  for(i=54;i<=56;i++)
				  if(col!=p[i].culoare)
					  caz=SE_NE;//cazul SE_NE//////////
			  nod *NE4=(nod*)malloc(sizeof(nod));
			  strcpy(NE4->index,"SE_NE");
			  SE->NE=NE4;
			  NE4->NW=NE4->NE=NE4->SW=NE4->SE=0;
			  if(caz!=SE_NE)
				  NE4->culoare=col;
				else
				 {NE4->culoare=9;
				  nod *crt=(nod*)malloc(sizeof(nod));
				  for(i=53;i<=56;i++)
					{char aux[3];
					 switch(i){case 53:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NE4->NW=crt;
									  break;}
							   case 54:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NE4->NE=crt;break;}
							   case 55:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NE4->SW=crt;break;}
							   case 56:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  NE4->SE=crt;break;}
							  }
					}
			    }
			  col=p[57].culoare;
			  for(i=58;i<=60;i++)
				  if(col!=p[i].culoare)
					  caz=SE_SW;////cazul SE_SW////
			  nod *SW4=(nod*)malloc(sizeof(nod));
			  strcpy(SW4->index,"SE_SW");
			  SE->SW=SW4;
			  SW4->NW=SW4->NE=SW4->SW=SW4->SE=0;
			  if(caz!=SE_SW)
				  SW4->culoare=col;
				else
				 {SW4->culoare=9;
				  nod *crt=(nod*)malloc(sizeof(nod));
				  for(i=57;i<=60;i++)
					{char aux[3];
					 switch(i){case 57:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SW4->NW=crt;
									  break;}
							   case 58:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SW4->NE=crt;break;}
							   case 59:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SW4->SW=crt;break;}
							   case 60:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SW4->SE=crt;break;}
							  }
					}
			     }
			  col=p[61].culoare;
			  for(i=61;i<=64;i++)
				  if(col!=p[i].culoare)
					  caz=SE_SE;/////cazul SE_SE///////
			  nod *SE4=(nod*)malloc(sizeof(nod));
			  strcpy(SE4->index,"SE_SE");
			  SE->SE=SE4;
			  SE4->NW=SE4->NE=SE4->SW=SE4->SE=0;
			  if(caz!=SE_SE)
				  SE4->culoare=col;
				else
				 {SE4->culoare=9;
				  nod *crt=(nod*)malloc(sizeof(nod));
				  for(i=61;i<=64;i++)
					{char aux[3];
					 switch(i){case 61:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SE4->NW=crt;
									  break;}
							   case 62:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SE4->NE=crt;break;}
							   case 63:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SE4->SW=crt;break;}
							   case 64:{nod *crt=(nod*)malloc(sizeof(nod));
									  crt->NW=crt->NE=crt->SW=crt->SE=0;
									  itoa(i,aux,10);
									  strcpy(crt->index,aux);
									  crt->culoare=p[i].culoare;
									  SE4->SE=crt;break;}
							  }
					}
			     }
		 }
			  
	}		  
}
void depthfirst(nod *root)
{if(root==NULL)
	 return;
 depthfirst(root->NW);
 depthfirst(root->NE);
 depthfirst(root->SW);
 depthfirst(root->SE);
}
void modifica_arbore(int nrnod,int culoarenod)
{nod *crt=head;nod *previous=NULL;
 if(head->NW==0)
				{nod *n1=(nod*)malloc(sizeof(nod));
				 n1->culoare=8;
				 strcpy(n1->index,"NW_H");
				 head->NW=n1;
				 nod *n2=(nod*)malloc(sizeof(nod));
				 n2->culoare=8;
				 strcpy(n2->index,"NE_H");
				 head->NE=n2;
				 nod *n3=(nod*)malloc(sizeof(nod));
				 n1->culoare=8;
				 strcpy(n3->index,"SW_H");
				 head->SW=n3;
				 nod *n4=(nod*)malloc(sizeof(nod));
				 n4->culoare=8;
				 strcpy(n4->index,"SE_H");
				 head->SE=n4;
				}
 if(nrnod<=16)
	 {head->NW->culoare=9;
	  crt=head->NW;
	  previous=head;
	  if(crt->NW==0)
				{nod *n1=(nod*)malloc(sizeof(nod));
				 n1->culoare=8;
				 strcpy(n1->index,"NW_NW");
				 crt->NW=n1;
				 nod *n2=(nod*)malloc(sizeof(nod));
				 n2->culoare=8;
				 strcpy(n2->index,"NW_NE");
				 crt->NE=n2;
				 nod *n3=(nod*)malloc(sizeof(nod));
				 n1->culoare=8;
				 strcpy(n3->index,"NW_SW");
				 crt->SW=n3;
				 nod *n4=(nod*)malloc(sizeof(nod));
				 n4->culoare=8;
				 strcpy(n4->index,"NW_SE");
				 crt->SE=n4;
				}
	  if(nrnod<=4){
		  previous=crt;crt=crt->NW;
		  if(crt->NW==0)
				{
				 nod *n1=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n1->index,"1");
				 crt->NW=n1;
				 nod *n2=(nod*)malloc(sizeof(nod));
				 n2->culoare=crt->culoare;
				 strcpy(n2->index,"2");
				 crt->NE=n2;
				 nod *n3=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n3->index,"3");
				 crt->SW=n3;
				 nod *n4=(nod*)malloc(sizeof(nod));
				 n4->culoare=crt->culoare;
				 strcpy(n4->index,"4");
				 crt->SE=n4;
				 switch(nrnod){case 1:n1->culoare=culoarenod;break;
							   case 2:n2->culoare=culoarenod;break;
							   case 3:n3->culoare=culoarenod;break;
							   case 4:n4->culoare=culoarenod;break;
							  }
				 crt->culoare=9;
				}
		  else
			  {switch(nrnod){case 1:crt->NW->culoare=culoarenod;break;
							case 2:crt->NE->culoare=culoarenod;break;
							case 3:crt->SW->culoare=culoarenod;break;
							case 4:crt->SE->culoare=culoarenod;break;
						   }
			   if(crt->NW->culoare==crt->NE->culoare&&crt->NW->culoare==crt->SW->culoare&&crt->NW->culoare==crt->SE->culoare)
					{crt->NW=crt->NE=crt->SW=crt->SE=0;
					 crt->culoare=culoarenod;
					 if(previous->NE->culoare==previous->SW->culoare&&previous->NE->culoare==previous->SE->culoare&&previous->NE->culoare==culoarenod)
							{previous->culoare=culoarenod;
							 previous->NW=previous->NE=previous->SW=previous->SE=0;
							 if(head->NE->culoare==head->SW->culoare&&head->NE->culoare==head->SE->culoare&&head->NE->culoare==culoarenod)
									{head->NW=head->NE=head->SW=head->SW=head->SE=0;
									 head->culoare=culoarenod;
									}
							}
					}
		  }}
	 if(nrnod>=5&&nrnod<=8){
			previous=crt;crt=crt->NE;
		  if(crt->NW==0)
				{
				 nod *n1=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n1->index,"5");
				 crt->NW=n1;
				 nod *n2=(nod*)malloc(sizeof(nod));
				 n2->culoare=crt->culoare;
				 strcpy(n2->index,"6");
				 crt->NE=n2;
				 nod *n3=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n3->index,"7");
				 crt->SW=n3;
				 nod *n4=(nod*)malloc(sizeof(nod));
				 n4->culoare=crt->culoare;
				 strcpy(n4->index,"8");
				 crt->SE=n4;
				 switch(nrnod){case 5:n1->culoare=culoarenod;break;
							   case 6:n2->culoare=culoarenod;break;
							   case 7:n3->culoare=culoarenod;break;
							   case 8:n4->culoare=culoarenod;break;
							  }
				 crt->culoare=9;
				}
		  else
			  {switch(nrnod){case 5:crt->NW->culoare=culoarenod;break;
							case 6:crt->NE->culoare=culoarenod;break;
							case 7:crt->SW->culoare=culoarenod;break;
							case 8:crt->SE->culoare=culoarenod;break;
						   }
			   if(crt->NW->culoare==crt->NE->culoare&&crt->NW->culoare==crt->SW->culoare&&crt->NW->culoare==crt->SE->culoare)
					{crt->NW=crt->NE=crt->SW=crt->SE=0;
					 crt->culoare=culoarenod;
					 if(previous->NW->culoare==previous->SW->culoare&&previous->NW->culoare==previous->SE->culoare&&previous->NW->culoare==culoarenod)
							{previous->culoare=culoarenod;
							 previous->NW=previous->NE=previous->SW=previous->SE=0;
							 if(head->NE->culoare==head->SW->culoare&&head->NE->culoare==head->SE->culoare&&head->NE->culoare==culoarenod)
									{head->NW=head->NE=head->SW=head->SW=head->SE=0;
									 head->culoare=culoarenod;
									}
							}
					}
		  }}
	 if(nrnod>=9&&nrnod<=12){
			previous=crt;crt=crt->SW;
		  if(crt->NW==0)
				{
				 nod *n1=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n1->index,"9");
				 crt->NW=n1;
				 nod *n2=(nod*)malloc(sizeof(nod));
				 n2->culoare=crt->culoare;
				 strcpy(n2->index,"10");
				 crt->NE=n2;
				 nod *n3=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n3->index,"11");
				 crt->SW=n3;
				 nod *n4=(nod*)malloc(sizeof(nod));
				 n4->culoare=crt->culoare;
				 strcpy(n4->index,"12");
				 crt->SE=n4;
				 switch(nrnod){case 9:n1->culoare=culoarenod;break;
							   case 10:n2->culoare=culoarenod;break;
							   case 11:n3->culoare=culoarenod;break;
							   case 12:n4->culoare=culoarenod;break;
							  }
				 crt->culoare=9;
				}
		  else
			  {switch(nrnod){case 9:crt->NW->culoare=culoarenod;break;
							case 10:crt->NE->culoare=culoarenod;break;
							case 11:crt->SW->culoare=culoarenod;break;
							case 12:crt->SE->culoare=culoarenod;break;
						   }
			   if(crt->NW->culoare==crt->NE->culoare&&crt->NW->culoare==crt->SW->culoare&&crt->NW->culoare==crt->SE->culoare)
					{crt->NW=crt->NE=crt->SW=crt->SE=0;
					 crt->culoare=culoarenod;
					 if(previous->NE->culoare==previous->NW->culoare&&previous->NE->culoare==previous->SE->culoare&&previous->NE->culoare==culoarenod)
							{previous->culoare=culoarenod;
							 previous->NW=previous->NE=previous->SW=previous->SE=0;
							 if(head->NE->culoare==head->SW->culoare&&head->NE->culoare==head->SE->culoare&&head->NE->culoare==culoarenod)
									{head->NW=head->NE=head->SW=head->SW=head->SE=0;
									 head->culoare=culoarenod;
									}
							}
					}
		  }}
	  if(nrnod>=13&&nrnod<=16){
	  previous=crt;crt=crt->SE;
		  if(crt->NW==0)
				{
				 nod *n1=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n1->index,"13");
				 crt->NW=n1;
				 nod *n2=(nod*)malloc(sizeof(nod));
				 n2->culoare=crt->culoare;
				 strcpy(n2->index,"14");
				 crt->NE=n2;
				 nod *n3=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n3->index,"15");
				 crt->SW=n3;
				 nod *n4=(nod*)malloc(sizeof(nod));
				 n4->culoare=crt->culoare;
				 strcpy(n4->index,"16");
				 crt->SE=n4;
				 switch(nrnod){case 13:n1->culoare=culoarenod;break;
							   case 14:n2->culoare=culoarenod;break;
							   case 15:n3->culoare=culoarenod;break;
							   case 16:n4->culoare=culoarenod;break;
							  }
				 crt->culoare=9;
				}
		  else
			  {switch(nrnod){case 13:crt->NW->culoare=culoarenod;break;
							case 14:crt->NE->culoare=culoarenod;break;
							case 15:crt->SW->culoare=culoarenod;break;
							case 16:crt->SE->culoare=culoarenod;break;
						   }
			   if(crt->NW->culoare==crt->NE->culoare&&crt->NW->culoare==crt->SW->culoare&&crt->NW->culoare==crt->SE->culoare)
					{crt->NW=crt->NE=crt->SW=crt->SE=0;
					 crt->culoare=culoarenod;
					 if(previous->NE->culoare==previous->SW->culoare&&previous->NE->culoare==previous->NW->culoare&&previous->NE->culoare==culoarenod)
							{previous->culoare=culoarenod;
							 previous->NW=previous->NE=previous->SW=previous->SE=0;
							 if(head->NE->culoare==head->SW->culoare&&head->NE->culoare==head->SE->culoare&&head->NE->culoare==culoarenod)
									{head->NW=head->NE=head->SW=head->SW=head->SE=0;
									 head->culoare=culoarenod;
									}
							}
					}
		  }}
	 }
 if(nrnod>=17&&nrnod<=32)
	 {head->NE->culoare=9;
	  crt=head->NE;
	  previous=head;
	  if(crt->NW==0)
				{nod *n1=(nod*)malloc(sizeof(nod));
				 n1->culoare=8;
				 strcpy(n1->index,"NE_NW");
				 crt->NW=n1;
				 nod *n2=(nod*)malloc(sizeof(nod));
				 n2->culoare=8;
				 strcpy(n2->index,"NE_NE");
				 crt->NE=n2;
				 nod *n3=(nod*)malloc(sizeof(nod));
				 n1->culoare=8;
				 strcpy(n3->index,"NE_SW");
				 crt->SW=n3;
				 nod *n4=(nod*)malloc(sizeof(nod));
				 n4->culoare=8;
				 strcpy(n4->index,"NE_SE");
				 crt->SE=n4;
				}
	  if(nrnod<=20){
		  previous=crt;crt=crt->NW;
		  if(crt->NW==0)
				{
				 nod *n1=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n1->index,"17");
				 crt->NW=n1;
				 nod *n2=(nod*)malloc(sizeof(nod));
				 n2->culoare=crt->culoare;
				 strcpy(n2->index,"18");
				 crt->NE=n2;
				 nod *n3=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n3->index,"19");
				 crt->SW=n3;
				 nod *n4=(nod*)malloc(sizeof(nod));
				 n4->culoare=crt->culoare;
				 strcpy(n4->index,"20");
				 crt->SE=n4;
				 switch(nrnod){case 17:n1->culoare=culoarenod;break;
							   case 18:n2->culoare=culoarenod;break;
							   case 19:n3->culoare=culoarenod;break;
							   case 20:n4->culoare=culoarenod;break;
							  }
				 crt->culoare=9;
				}
		  else
			  {switch(nrnod){case 17:crt->NW->culoare=culoarenod;break;
							case 18:crt->NE->culoare=culoarenod;break;
							case 19:crt->SW->culoare=culoarenod;break;
							case 20:crt->SE->culoare=culoarenod;break;
						   }
			   if(crt->NW->culoare==crt->NE->culoare&&crt->NW->culoare==crt->SW->culoare&&crt->NW->culoare==crt->SE->culoare)
					{crt->NW=crt->NE=crt->SW=crt->SE=0;
					 crt->culoare=culoarenod;
					 if(previous->NE->culoare==previous->SW->culoare&&previous->NE->culoare==previous->SE->culoare&&previous->NE->culoare==culoarenod)
							{previous->culoare=culoarenod;
							 previous->NW=previous->NE=previous->SW=previous->SE=0;
							 if(head->NE->culoare==head->SW->culoare&&head->NE->culoare==head->SE->culoare&&head->NE->culoare==culoarenod)
									{head->NW=head->NE=head->SW=head->SW=head->SE=0;
									 head->culoare=culoarenod;
									}
							}
					}
		  }}
	 if(nrnod>=21&&nrnod<=24){
			previous=crt;crt=crt->NE;
		  if(crt->NW==0)
				{
				 nod *n1=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n1->index,"21");
				 crt->NW=n1;
				 nod *n2=(nod*)malloc(sizeof(nod));
				 n2->culoare=crt->culoare;
				 strcpy(n2->index,"22");
				 crt->NE=n2;
				 nod *n3=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n3->index,"23");
				 crt->SW=n3;
				 nod *n4=(nod*)malloc(sizeof(nod));
				 n4->culoare=crt->culoare;
				 strcpy(n4->index,"24");
				 crt->SE=n4;
				 switch(nrnod){case 21:n1->culoare=culoarenod;break;
							   case 22:n2->culoare=culoarenod;break;
							   case 23:n3->culoare=culoarenod;break;
							   case 24:n4->culoare=culoarenod;break;
							  }
				 crt->culoare=9;
				}
		  else
			  {switch(nrnod){case 21:crt->NW->culoare=culoarenod;break;
							case 22:crt->NE->culoare=culoarenod;break;
							case 23:crt->SW->culoare=culoarenod;break;
							case 24:crt->SE->culoare=culoarenod;break;
						   }
			   if(crt->NW->culoare==crt->NE->culoare&&crt->NW->culoare==crt->SW->culoare&&crt->NW->culoare==crt->SE->culoare)
					{crt->NW=crt->NE=crt->SW=crt->SE=0;
					 crt->culoare=culoarenod;
					 if(previous->NW->culoare==previous->SW->culoare&&previous->NW->culoare==previous->SE->culoare&&previous->NW->culoare==culoarenod)
							{previous->culoare=culoarenod;
							 previous->NW=previous->NE=previous->SW=previous->SE=0;
							 if(head->NE->culoare==head->SW->culoare&&head->NE->culoare==head->SE->culoare&&head->NE->culoare==culoarenod)
									{head->NW=head->NE=head->SW=head->SW=head->SE=0;
									 head->culoare=culoarenod;
									}
							}
					}
		  }}
	 if(nrnod>=25&&nrnod<=28){
			previous=crt;crt=crt->SW;
		  if(crt->NW==0)
				{
				 nod *n1=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n1->index,"25");
				 crt->NW=n1;
				 nod *n2=(nod*)malloc(sizeof(nod));
				 n2->culoare=crt->culoare;
				 strcpy(n2->index,"26");
				 crt->NE=n2;
				 nod *n3=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n3->index,"27");
				 crt->SW=n3;
				 nod *n4=(nod*)malloc(sizeof(nod));
				 n4->culoare=crt->culoare;
				 strcpy(n4->index,"28");
				 crt->SE=n4;
				 switch(nrnod){case 25:n1->culoare=culoarenod;break;
							   case 26:n2->culoare=culoarenod;break;
							   case 27:n3->culoare=culoarenod;break;
							   case 28:n4->culoare=culoarenod;break;
							  }
				 crt->culoare=9;
				}
		  else
			  {switch(nrnod){case 25:crt->NW->culoare=culoarenod;break;
							case 26:crt->NE->culoare=culoarenod;break;
							case 27:crt->SW->culoare=culoarenod;break;
							case 28:crt->SE->culoare=culoarenod;break;
						   }
			   if(crt->NW->culoare==crt->NE->culoare&&crt->NW->culoare==crt->SW->culoare&&crt->NW->culoare==crt->SE->culoare)
					{crt->NW=crt->NE=crt->SW=crt->SE=0;
					 crt->culoare=culoarenod;
					 if(previous->NE->culoare==previous->NW->culoare&&previous->NE->culoare==previous->SE->culoare&&previous->NE->culoare==culoarenod)
							{previous->culoare=culoarenod;
							 previous->NW=previous->NE=previous->SW=previous->SE=0;
							 if(head->NE->culoare==head->SW->culoare&&head->NE->culoare==head->SE->culoare&&head->NE->culoare==culoarenod)
									{head->NW=head->NE=head->SW=head->SW=head->SE=0;
									 head->culoare=culoarenod;
									}
							}
					}
		  }}
	  if(nrnod>=29&&nrnod<=32){
	  previous=crt;crt=crt->SE;
		  if(crt->NW==0)
				{
				 nod *n1=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n1->index,"29");
				 crt->NW=n1;
				 nod *n2=(nod*)malloc(sizeof(nod));
				 n2->culoare=crt->culoare;
				 strcpy(n2->index,"30");
				 crt->NE=n2;
				 nod *n3=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n3->index,"31");
				 crt->SW=n3;
				 nod *n4=(nod*)malloc(sizeof(nod));
				 n4->culoare=crt->culoare;
				 strcpy(n4->index,"32");
				 crt->SE=n4;
				 switch(nrnod){case 29:n1->culoare=culoarenod;break;
							   case 30:n2->culoare=culoarenod;break;
							   case 31:n3->culoare=culoarenod;break;
							   case 32:n4->culoare=culoarenod;break;
							  }
				 crt->culoare=9;
				}
		  else
			  {switch(nrnod){case 29:crt->NW->culoare=culoarenod;break;
							case 30:crt->NE->culoare=culoarenod;break;
							case 31:crt->SW->culoare=culoarenod;break;
							case 32:crt->SE->culoare=culoarenod;break;
						   }
			   if(crt->NW->culoare==crt->NE->culoare&&crt->NW->culoare==crt->SW->culoare&&crt->NW->culoare==crt->SE->culoare)
					{crt->NW=crt->NE=crt->SW=crt->SE=0;
					 crt->culoare=culoarenod;
					 if(previous->NE->culoare==previous->SW->culoare&&previous->NE->culoare==previous->NW->culoare&&previous->NE->culoare==culoarenod)
							{previous->culoare=culoarenod;
							 previous->NW=previous->NE=previous->SW=previous->SE=0;
							 if(head->NE->culoare==head->SW->culoare&&head->NE->culoare==head->SE->culoare&&head->NE->culoare==culoarenod)
									{head->NW=head->NE=head->SW=head->SW=head->SE=0;
									 head->culoare=culoarenod;
									}
							}
					}
		  }}
	 }
	 if(nrnod>=33&&nrnod<=48)
	 {head->SW->culoare=9;
	  crt=head->SW;
	  previous=head;
	  if(crt->NW==0)
				{nod *n1=(nod*)malloc(sizeof(nod));
				 n1->culoare=8;
				 strcpy(n1->index,"SW_NW");
				 crt->NW=n1;
				 nod *n2=(nod*)malloc(sizeof(nod));
				 n2->culoare=8;
				 strcpy(n2->index,"SW_NE");
				 crt->NE=n2;
				 nod *n3=(nod*)malloc(sizeof(nod));
				 n1->culoare=8;
				 strcpy(n3->index,"SW_SW");
				 crt->SW=n3;
				 nod *n4=(nod*)malloc(sizeof(nod));
				 n4->culoare=8;
				 strcpy(n4->index,"SW_SE");
				 crt->SE=n4;
				}
	  if(nrnod<=36){
		  previous=crt;crt=crt->NW;
		  if(crt->NW==0)
				{
				 nod *n1=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n1->index,"33");
				 crt->NW=n1;
				 nod *n2=(nod*)malloc(sizeof(nod));
				 n2->culoare=crt->culoare;
				 strcpy(n2->index,"34");
				 crt->NE=n2;
				 nod *n3=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n3->index,"35");
				 crt->SW=n3;
				 nod *n4=(nod*)malloc(sizeof(nod));
				 n4->culoare=crt->culoare;
				 strcpy(n4->index,"36");
				 crt->SE=n4;
				 switch(nrnod){case 33:n1->culoare=culoarenod;break;
							   case 34:n2->culoare=culoarenod;break;
							   case 35:n3->culoare=culoarenod;break;
							   case 36:n4->culoare=culoarenod;break;
							  }
				 crt->culoare=9;
				}
		  else
			  {switch(nrnod){case 33:crt->NW->culoare=culoarenod;break;
							case 34:crt->NE->culoare=culoarenod;break;
							case 35:crt->SW->culoare=culoarenod;break;
							case 36:crt->SE->culoare=culoarenod;break;
						   }
			   if(crt->NW->culoare==crt->NE->culoare&&crt->NW->culoare==crt->SW->culoare&&crt->NW->culoare==crt->SE->culoare)
					{crt->NW=crt->NE=crt->SW=crt->SE=0;
					 crt->culoare=culoarenod;
					 if(previous->NE->culoare==previous->SW->culoare&&previous->NE->culoare==previous->SE->culoare&&previous->NE->culoare==culoarenod)
							{previous->culoare=culoarenod;
							 previous->NW=previous->NE=previous->SW=previous->SE=0;
							 if(head->NE->culoare==head->SW->culoare&&head->NE->culoare==head->SE->culoare&&head->NE->culoare==culoarenod)
									{head->NW=head->NE=head->SW=head->SW=head->SE=0;
									 head->culoare=culoarenod;
									}
							}
					}
		  }}
	 if(nrnod>=37&&nrnod<=40){
			previous=crt;crt=crt->NE;
		  if(crt->NW==0)
				{
				 nod *n1=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n1->index,"37");
				 crt->NW=n1;
				 nod *n2=(nod*)malloc(sizeof(nod));
				 n2->culoare=crt->culoare;
				 strcpy(n2->index,"38");
				 crt->NE=n2;
				 nod *n3=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n3->index,"39");
				 crt->SW=n3;
				 nod *n4=(nod*)malloc(sizeof(nod));
				 n4->culoare=crt->culoare;
				 strcpy(n4->index,"40");
				 crt->SE=n4;
				 switch(nrnod){case 37:n1->culoare=culoarenod;break;
							   case 38:n2->culoare=culoarenod;break;
							   case 39:n3->culoare=culoarenod;break;
							   case 40:n4->culoare=culoarenod;break;
							  }
				 crt->culoare=9;
				}
		  else
			  {switch(nrnod){case 37:crt->NW->culoare=culoarenod;break;
							case 38:crt->NE->culoare=culoarenod;break;
							case 39:crt->SW->culoare=culoarenod;break;
							case 40:crt->SE->culoare=culoarenod;break;
						   }
			   if(crt->NW->culoare==crt->NE->culoare&&crt->NW->culoare==crt->SW->culoare&&crt->NW->culoare==crt->SE->culoare)
					{crt->NW=crt->NE=crt->SW=crt->SE=0;
					 crt->culoare=culoarenod;
					 if(previous->NW->culoare==previous->SW->culoare&&previous->NW->culoare==previous->SE->culoare&&previous->NW->culoare==culoarenod)
							{previous->culoare=culoarenod;
							 previous->NW=previous->NE=previous->SW=previous->SE=0;
							 if(head->NE->culoare==head->SW->culoare&&head->NE->culoare==head->SE->culoare&&head->NE->culoare==culoarenod)
									{head->NW=head->NE=head->SW=head->SW=head->SE=0;
									 head->culoare=culoarenod;
									}
							}
					}
		  }}
	 if(nrnod>=41&&nrnod<=44){
			previous=crt;crt=crt->SW;
		  if(crt->NW==0)
				{
				 nod *n1=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n1->index,"41");
				 crt->NW=n1;
				 nod *n2=(nod*)malloc(sizeof(nod));
				 n2->culoare=crt->culoare;
				 strcpy(n2->index,"42");
				 crt->NE=n2;
				 nod *n3=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n3->index,"43");
				 crt->SW=n3;
				 nod *n4=(nod*)malloc(sizeof(nod));
				 n4->culoare=crt->culoare;
				 strcpy(n4->index,"44");
				 crt->SE=n4;
				 switch(nrnod){case 41:n1->culoare=culoarenod;break;
							   case 42:n2->culoare=culoarenod;break;
							   case 43:n3->culoare=culoarenod;break;
							   case 44:n4->culoare=culoarenod;break;
							  }
				 crt->culoare=9;
				}
		  else
			  {switch(nrnod){case 41:crt->NW->culoare=culoarenod;break;
							case 42:crt->NE->culoare=culoarenod;break;
							case 43:crt->SW->culoare=culoarenod;break;
							case 44:crt->SE->culoare=culoarenod;break;
						   }
			   if(crt->NW->culoare==crt->NE->culoare&&crt->NW->culoare==crt->SW->culoare&&crt->NW->culoare==crt->SE->culoare)
					{crt->NW=crt->NE=crt->SW=crt->SE=0;
					 crt->culoare=culoarenod;
					 if(previous->NE->culoare==previous->NW->culoare&&previous->NE->culoare==previous->SE->culoare&&previous->NE->culoare==culoarenod)
							{previous->culoare=culoarenod;
							 previous->NW=previous->NE=previous->SW=previous->SE=0;
							 if(head->NE->culoare==head->SW->culoare&&head->NE->culoare==head->SE->culoare&&head->NE->culoare==culoarenod)
									{head->NW=head->NE=head->SW=head->SW=head->SE=0;
									 head->culoare=culoarenod;
									}
							}
					}
		  }}
	  if(nrnod>=45&&nrnod<=48){
	  previous=crt;crt=crt->SE;
		  if(crt->NW==0)
				{
				 nod *n1=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n1->index,"45");
				 crt->NW=n1;
				 nod *n2=(nod*)malloc(sizeof(nod));
				 n2->culoare=crt->culoare;
				 strcpy(n2->index,"46");
				 crt->NE=n2;
				 nod *n3=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n3->index,"47");
				 crt->SW=n3;
				 nod *n4=(nod*)malloc(sizeof(nod));
				 n4->culoare=crt->culoare;
				 strcpy(n4->index,"48");
				 crt->SE=n4;
				 switch(nrnod){case 45:n1->culoare=culoarenod;break;
							   case 46:n2->culoare=culoarenod;break;
							   case 47:n3->culoare=culoarenod;break;
							   case 48:n4->culoare=culoarenod;break;
							  }
				 crt->culoare=9;
				}
		  else
			  {switch(nrnod){case 45:crt->NW->culoare=culoarenod;break;
							case 46:crt->NE->culoare=culoarenod;break;
							case 47:crt->SW->culoare=culoarenod;break;
							case 48:crt->SE->culoare=culoarenod;break;
						   }
			   if(crt->NW->culoare==crt->NE->culoare&&crt->NW->culoare==crt->SW->culoare&&crt->NW->culoare==crt->SE->culoare)
					{crt->NW=crt->NE=crt->SW=crt->SE=0;
					 crt->culoare=culoarenod;
					 if(previous->NE->culoare==previous->SW->culoare&&previous->NE->culoare==previous->NW->culoare&&previous->NE->culoare==culoarenod)
							{previous->culoare=culoarenod;
							 previous->NW=previous->NE=previous->SW=previous->SE=0;
							 if(head->NE->culoare==head->SW->culoare&&head->NE->culoare==head->SE->culoare&&head->NE->culoare==culoarenod)
									{head->NW=head->NE=head->SW=head->SW=head->SE=0;
									 head->culoare=culoarenod;
									}
							}
					}
		  }}
	 }
	 if(nrnod>=49&&nrnod<=64)
	 {head->NE->culoare=9;
	  crt=head->SE;
	  previous=head;
	  if(crt->NW==0)
				{nod *n1=(nod*)malloc(sizeof(nod));
				 n1->culoare=8;
				 strcpy(n1->index,"SE_NW");
				 crt->NW=n1;
				 nod *n2=(nod*)malloc(sizeof(nod));
				 n2->culoare=8;
				 strcpy(n2->index,"SE_NE");
				 crt->NE=n2;
				 nod *n3=(nod*)malloc(sizeof(nod));
				 n1->culoare=8;
				 strcpy(n3->index,"SE_SW");
				 crt->SW=n3;
				 nod *n4=(nod*)malloc(sizeof(nod));
				 n4->culoare=8;
				 strcpy(n4->index,"SE_SE");
				 crt->SE=n4;
				}
	  if(nrnod<=52){
		  previous=crt;crt=crt->NW;
		  if(crt->NW==0)
				{
				 nod *n1=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n1->index,"49");
				 crt->NW=n1;
				 nod *n2=(nod*)malloc(sizeof(nod));
				 n2->culoare=crt->culoare;
				 strcpy(n2->index,"50");
				 crt->NE=n2;
				 nod *n3=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n3->index,"51");
				 crt->SW=n3;
				 nod *n4=(nod*)malloc(sizeof(nod));
				 n4->culoare=crt->culoare;
				 strcpy(n4->index,"52");
				 crt->SE=n4;
				 switch(nrnod){case 49:n1->culoare=culoarenod;break;
							   case 50:n2->culoare=culoarenod;break;
							   case 51:n3->culoare=culoarenod;break;
							   case 52:n4->culoare=culoarenod;break;
							  }
				 crt->culoare=9;
				}
		  else
			  {switch(nrnod){case 49:crt->NW->culoare=culoarenod;break;
							case 50:crt->NE->culoare=culoarenod;break;
							case 51:crt->SW->culoare=culoarenod;break;
							case 52:crt->SE->culoare=culoarenod;break;
						   }
			   if(crt->NW->culoare==crt->NE->culoare&&crt->NW->culoare==crt->SW->culoare&&crt->NW->culoare==crt->SE->culoare)
					{crt->NW=crt->NE=crt->SW=crt->SE=0;
					 crt->culoare=culoarenod;
					 if(previous->NE->culoare==previous->SW->culoare&&previous->NE->culoare==previous->SE->culoare&&previous->NE->culoare==culoarenod)
							{previous->culoare=culoarenod;
							 previous->NW=previous->NE=previous->SW=previous->SE=0;
							 if(head->NE->culoare==head->SW->culoare&&head->NE->culoare==head->SE->culoare&&head->NE->culoare==culoarenod)
									{head->NW=head->NE=head->SW=head->SW=head->SE=0;
									 head->culoare=culoarenod;
									}
							}
					}
		  }}
	 if(nrnod>=53&&nrnod<=56){
			previous=crt;crt=crt->NE;
		  if(crt->NW==0)
				{
				 nod *n1=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n1->index,"53");
				 crt->NW=n1;
				 nod *n2=(nod*)malloc(sizeof(nod));
				 n2->culoare=crt->culoare;
				 strcpy(n2->index,"54");
				 crt->NE=n2;
				 nod *n3=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n3->index,"55");
				 crt->SW=n3;
				 nod *n4=(nod*)malloc(sizeof(nod));
				 n4->culoare=crt->culoare;
				 strcpy(n4->index,"56");
				 crt->SE=n4;
				 switch(nrnod){case 53:n1->culoare=culoarenod;break;
							   case 54:n2->culoare=culoarenod;break;
							   case 55:n3->culoare=culoarenod;break;
							   case 56:n4->culoare=culoarenod;break;
							  }
				 crt->culoare=9;
				}
		  else
			  {switch(nrnod){case 53:crt->NW->culoare=culoarenod;break;
							case 54:crt->NE->culoare=culoarenod;break;
							case 55:crt->SW->culoare=culoarenod;break;
							case 56:crt->SE->culoare=culoarenod;break;
						   }
			   if(crt->NW->culoare==crt->NE->culoare&&crt->NW->culoare==crt->SW->culoare&&crt->NW->culoare==crt->SE->culoare)
					{crt->NW=crt->NE=crt->SW=crt->SE=0;
					 crt->culoare=culoarenod;
					 if(previous->NW->culoare==previous->SW->culoare&&previous->NW->culoare==previous->SE->culoare&&previous->NW->culoare==culoarenod)
							{previous->culoare=culoarenod;
							 previous->NW=previous->NE=previous->SW=previous->SE=0;
							 if(head->NE->culoare==head->SW->culoare&&head->NE->culoare==head->SE->culoare&&head->NE->culoare==culoarenod)
									{head->NW=head->NE=head->SW=head->SW=head->SE=0;
									 head->culoare=culoarenod;
									}
							}
					}
		  }}
	 if(nrnod>=57&&nrnod<=60){
			previous=crt;crt=crt->SW;
		  if(crt->NW==0)
				{
				 nod *n1=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n1->index,"57");
				 crt->NW=n1;
				 nod *n2=(nod*)malloc(sizeof(nod));
				 n2->culoare=crt->culoare;
				 strcpy(n2->index,"58");
				 crt->NE=n2;
				 nod *n3=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n3->index,"59");
				 crt->SW=n3;
				 nod *n4=(nod*)malloc(sizeof(nod));
				 n4->culoare=crt->culoare;
				 strcpy(n4->index,"60");
				 crt->SE=n4;
				 switch(nrnod){case 57:n1->culoare=culoarenod;break;
							   case 58:n2->culoare=culoarenod;break;
							   case 59:n3->culoare=culoarenod;break;
							   case 60:n4->culoare=culoarenod;break;
							  }
				 crt->culoare=9;
				}
		  else
			  {switch(nrnod){case 57:crt->NW->culoare=culoarenod;break;
							case 58:crt->NE->culoare=culoarenod;break;
							case 59:crt->SW->culoare=culoarenod;break;
							case 60:crt->SE->culoare=culoarenod;break;
						   }
			   if(crt->NW->culoare==crt->NE->culoare&&crt->NW->culoare==crt->SW->culoare&&crt->NW->culoare==crt->SE->culoare)
					{crt->NW=crt->NE=crt->SW=crt->SE=0;
					 crt->culoare=culoarenod;
					 if(previous->NE->culoare==previous->NW->culoare&&previous->NE->culoare==previous->SE->culoare&&previous->NE->culoare==culoarenod)
							{previous->culoare=culoarenod;
							 previous->NW=previous->NE=previous->SW=previous->SE=0;
							 if(head->NE->culoare==head->SW->culoare&&head->NE->culoare==head->SE->culoare&&head->NE->culoare==culoarenod)
									{head->NW=head->NE=head->SW=head->SW=head->SE=0;
									 head->culoare=culoarenod;
									}
							}
					}
		  }}
	  if(nrnod>=29&&nrnod<=32){
	  previous=crt;crt=crt->SE;
		  if(crt->NW==0)
				{
				 nod *n1=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n1->index,"57");
				 crt->NW=n1;
				 nod *n2=(nod*)malloc(sizeof(nod));
				 n2->culoare=crt->culoare;
				 strcpy(n2->index,"58");
				 crt->NE=n2;
				 nod *n3=(nod*)malloc(sizeof(nod));
				 n1->culoare=crt->culoare;
				 strcpy(n3->index,"59");
				 crt->SW=n3;
				 nod *n4=(nod*)malloc(sizeof(nod));
				 n4->culoare=crt->culoare;
				 strcpy(n4->index,"60");
				 crt->SE=n4;
				 switch(nrnod){case 57:n1->culoare=culoarenod;break;
							   case 58:n2->culoare=culoarenod;break;
							   case 59:n3->culoare=culoarenod;break;
							   case 60:n4->culoare=culoarenod;break;
							  }
				 crt->culoare=9;
				}
		  else
			  {switch(nrnod){case 57:crt->NW->culoare=culoarenod;break;
							case 58:crt->NE->culoare=culoarenod;break;
							case 59:crt->SW->culoare=culoarenod;break;
							case 60:crt->SE->culoare=culoarenod;break;
						   }
			   if(crt->NW->culoare==crt->NE->culoare&&crt->NW->culoare==crt->SW->culoare&&crt->NW->culoare==crt->SE->culoare)
					{crt->NW=crt->NE=crt->SW=crt->SE=0;
					 crt->culoare=culoarenod;
					 if(previous->NE->culoare==previous->SW->culoare&&previous->NE->culoare==previous->NW->culoare&&previous->NE->culoare==culoarenod)
							{previous->culoare=culoarenod;
							 previous->NW=previous->NE=previous->SW=previous->SE=0;
							 if(head->NE->culoare==head->SW->culoare&&head->NE->culoare==head->SE->culoare&&head->NE->culoare==culoarenod)
									{head->NW=head->NE=head->SW=head->SW=head->SE=0;
									 head->culoare=culoarenod;
									}
							}
					}
		  }}
	 }
}
int nr;
BOOL CALLBACK DialogProc2( HWND hWnd3, UINT msg, WPARAM wParam, LPARAM lParam )
{char culoarenod[10];
 switch(msg){
	 case WM_INITDIALOG:return TRUE;
	 case WM_COMMAND:{
		 switch(wParam){
						case IDC_BUTTON1:{GetDlgItemText(hWnd3,IDC_EDIT1,indexnod,10);
										 if(strcmp(indexnod,"")!=0)
											   {nr=atoi(indexnod);
												MessageBox(hWnd3,"Indexul a fost introdus","OK",NULL);aux=1;
											    if(nr<1||nr>64)
											         {MessageBox(hWnd3,"Indexul introdus nu exista","Eroare",NULL);aux=0;}
											   }
											else
											   {MessageBox(hWnd3,"Nu a-ti introdus nimic","Not OK",NULL);aux=0;}
										 break;}
						case IDC_BUTTON2:{GetDlgItemText(hWnd3,IDC_EDIT2,culoarenod,10);
										 if(strcmp(culoarenod,"")!=0)
											  {MessageBox(hWnd3,"Culoarea a fost introdusa","OK",NULL);aux2=1;}
											else
											  {MessageBox(hWnd3,"Nu a-ti introdus nimic","Not OK",NULL);aux2=0;}
										  if(strcmp(culoarenod,"negru")==0)
												{col=1;break;}
										  if(strcmp(culoarenod,"rosu")==0)
												{col=2;break;}
										  if(strcmp(culoarenod,"verde")==0)
												{col=3;break;}
										  if(strcmp(culoarenod,"albastru")==0)
												{col=4;break;}
										  if(strcmp(culoarenod,"galben")==0)
												{col=5;;break;}
										  if(strcmp(culoarenod,"violet")==0)
												{col=6;break;}
										  if(strcmp(culoarenod,"bleumarin")==0)
												{col=7;break;}
										  if(strcmp(culoarenod,"alb")==0)
												{MessageBox(hWnd3,"Dati o culoare diferita de alb","Eroare",NULL);break;}
										  MessageBox(hWnd3,"Culoarea nu exista","Eroare",NULL);
										  aux2=0;
										  break;}
						case IDC_BUTTON3:if(aux!=1||aux2!=1)
											 {MessageBox(hWnd3,"Inainte de a continua verificati ca a-ti introdus indexul si culoarea","Eroare",NULL);
											  break;
											 }
										  else
											  {//nr=atoi(indexnod);
											   if(p[nr].culoare!=8)
													MessageBox(hWnd2,"Nodul este deja colorat.Operatia doar ii va schimba culoarea","Atentie!!!",NULL);
											   p[nr].culoare=col;
											   ok=2;/*modifica_arbore(nr,col);*/InvalidateRect(hWnd2,NULL,FALSE);
											   aux3=1;InvalidateRect(hWnd2,NULL,FALSE);
											   EndDialog(Dialog2,0);
											   InvalidateRect(hWnd2,NULL,FALSE);
											   break;
											  }
					    }
		 break;
					}
	 case WM_CLOSE:EndDialog(Dialog2,0);
}
 return 0;
}
BOOL CALLBACK DialogProc3( HWND hWnd4, UINT msg, WPARAM wParam, LPARAM lParam )
{strcpy(indexnod,"");
 switch(msg)
		{case WM_INITDIALOG:return TRUE;
		 case WM_CLOSE: EndDialog(Dialog3,0);
		 case WM_COMMAND:
			 switch(wParam){
				case IDC_BUTTON1: GetDlgItemText(hWnd4,IDC_EDIT1,indexnod,10);
								  if(strcmp(indexnod,"")!=0)
											   {nr=atoi(indexnod);
												MessageBox(hWnd3,"Indexul a fost introdus","OK",NULL);
											   }
											else
											   MessageBox(hWnd3,"Nu a-ti introdus nimic","Not OK",NULL);
									break;
				case IDC_BUTTON2:
								  if(p[nr].culoare==8)
										MessageBox(hWnd3,"Nodul este deja alb(nu se gaseste in arbore)","Eroare",NULL);
									else
									   {p[nr].culoare=8;
										aux4=1;InvalidateRect(hWnd2,NULL,FALSE);
										ok=2;InvalidateRect(hWnd2,NULL,FALSE);
										EndDialog(Dialog3,0);
										InvalidateRect(hWnd2,NULL,FALSE);
										break;
									   }
						   }
		 break;
		}
  return 0;
}

//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd2, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc,DC;
	switch (message)
	{
	case WM_COMMAND:
		
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// Parse the menu selections:
		switch (wmId)
		{
		case IDM_ABOUT:
			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd2, About);
			break;
		case IDM_EXIT:
				{
					MessageBox(hWnd2,"Va multumim!","Bye Bye", NULL);
					DestroyWindow(hWnd2);
				}
			break;
		case ID_OPERATII_ADAUGANOD:
				{aux=0;
				 for(int i=1;i<=64;i++)
					 if(p[i].culoare!=8)
							aux=1;
				 if(aux==0)
						{MessageBox(hWnd2,"Imaginea nu a fost creata","Eroare",NULL);
						 break;
						}
				 aux=0;aux2=0;
				 Dialog2=CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_PROPPAGE_LARGE1),hWnd2,reinterpret_cast<DLGPROC>(DialogProc2));
				 ShowWindow(Dialog2,SW_SHOW);
				 break;
				}
		case ID_OPERATII_STERGENOD:
				{aux4=0;
				 for(int i=1;i<=64;i++)
					 if(p[i].culoare!=8)
						 aux4=1;
				 if(aux4==0)
					 {MessageBox(hWnd2,"Imaginea e goala.Nu aveti ce sterge.","Eroare",NULL);
					  break;
					 }
				 Dialog3=CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_PROPPAGE_LARGE2),hWnd2,reinterpret_cast<DLGPROC>(DialogProc3));
				 ShowWindow(Dialog3,SW_SHOW);
				 break;
				}
		case ID_FILE_CREAREHARTA:
				{grid=1;initt=1;
				 for(int i=1;i<=64;i++)
					 p[i].culoare=8;
				 Dialog=CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_PROPPAGE_LARGE), hWnd2,reinterpret_cast<DLGPROC>(DialogProc));
				 if(Dialog==NULL)
					 MessageBox(hWnd2,"eroare dialog","eroare",NULL);
				 ShowWindow(Dialog,SW_SHOW);
				 InvalidateRect(hWnd2,NULL,FALSE);
				 break;
				}
		default:
			return DefWindowProc(hWnd2, message, wParam, lParam);
		break;
		}
		case WM_PAINT:{
			HPEN blackPen;
		hdc = BeginPaint(hWnd2, &ps);
		// TODO: Add any drawing code here...
		if(initt!=1){
		char text[100];
		strcpy(text,"Bine ati venit!");
		TextOut(hdc,630,280,text,strlen(text));
		strcpy(text,"Pentru a incepe demonstratia");
		TextOut(hdc,580,300,text,strlen(text));
		strcpy(text,"Va rugam selectati optiunea creare harta din meniul file");
		TextOut(hdc,480,320,text,strlen(text));}
		if(grid==1){HBRUSH alb=CreateSolidBrush(RGB(255,255,255));
					r=(RECT*)malloc(sizeof(RECT));
					r->left=0;r->top=0;r->right=2000;r->bottom=750;
					FillRect(hdc,r,alb);
					free(r);
			   int t,y;
			   t=1000;
			   y=25;
			   for(int i=1;i<=8;i++)
			   {
				   for(int j=1;j<=8;j++)
				   {
					   Rectangle(hdc,t,y,t+25,y+25);
					   t=t+25;
				   }
				   y=y+25;
				   t=1000;
			   }
			   grid=0;
		   }
		if(ok==1){
			 colorare(hdc,ps,R,G,B,left,top,right,bottom);
			 ok=0;
			 //InvalidateRect(hWnd2,NULL,TRUE);
			 Dialog=CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_PROPPAGE_LARGE), hWnd2,reinterpret_cast<DLGPROC>(DialogProc));
			 if(Dialog==NULL)
					 MessageBox(hWnd2,"eroare dialog","eroare",NULL);
			 ShowWindow(Dialog,SW_SHOW);
			 UpdateWindow(hWnd2);
			}
		if(aux4==1)
				 {colorare(hdc,ps,255,255,255,p[nr].left,p[nr].top,p[nr].right,p[nr].bottom);
				  aux4=0;}
		if(aux3==1)
				 {colorare(hdc,ps,c[col].R,c[col].G,c[col].B,p[nr].left,p[nr].top,p[nr].right,p[nr].bottom);
				  aux3=0;}
		if(ok==2||ok==3){if(ok==2)
							colorare_arbore();
				  char g[10];
				  HBRUSH a=CreateSolidBrush(RGB(255,255,255));
				  r=(RECT*)malloc(sizeof(RECT));
				  r->left=0;r->top=270;r->right=1500;r->bottom=750;
				  FillRect(hdc,r,a);
				  strcpy(g,head->index);
						//g[1]=NULL;
						TextOut(hdc,609,255,g,strlen(g));
						SetTextColor(hdc,RGB(0,0,255));

						nod *crt,*prev,*root2;
						crt=(nod*)malloc(sizeof(nod));
						root2=(nod*)malloc(sizeof(nod));
						crt=head;
						colorare(hdc,ps,c[head->culoare].R,c[head->culoare].G,c[head->culoare].B,620,270,635,285);
						if(head->NW!=NULL)
						{
							
							
							int p,q;char v[10];
							p=180;q=330;
								colorare(hdc,ps,c[crt->NW->culoare].R,c[crt->NW->culoare].G,c[crt->NW->culoare].B,p,q,p+15,q+15);
								root2=crt->NW;
								strcpy(v,root2->index);
								TextOut(hdc,p-9,q-20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            p=p+300;
								colorare(hdc,ps,c[crt->NE->culoare].R,c[crt->NE->culoare].G,c[crt->NE->culoare].B,p,q,p+15,q+15);
								root2=crt->NE;
								strcpy(v,root2->index);
								TextOut(hdc,p-9,q-20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            p=p+300;
								colorare(hdc,ps,c[crt->SW->culoare].R,c[crt->SW->culoare].G,c[crt->SW->culoare].B,p,q,p+15,q+15);
								root2=crt->SW;
								strcpy(v,root2->index);
								TextOut(hdc,p-9,q-20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            p=p+300;
								colorare(hdc,ps,c[crt->SE->culoare].R,c[crt->SE->culoare].G,c[crt->SE->culoare].B,p,q,p+15,q+15);
								root2=crt->SE;
								strcpy(v,root2->index);
								TextOut(hdc,p-9,q-20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
								p=187;q=330;
				                 for(int i=1;i<=4;i++)
					               {
						               MoveToEx(hdc,627,285,NULL);
				                       LineTo(hdc,p,q);
					                   p=p+300;
				                   }

						}
						prev=(nod*)malloc(sizeof(nod));
						prev=crt;
						char v[10];
						int x,y;
						if(prev->NW!=NULL)
						{
						crt=prev->NW;
						char v[10];
						int x,y;
						x=100;y=420;
						if(crt->NW!=NULL)
						{
							colorare(hdc,ps,c[crt->NW->culoare].R,c[crt->NW->culoare].G,c[crt->NW->culoare].B,x,y,x+15,y+15);
								root2=crt->NW;
								strcpy(v,root2->index);
								TextOut(hdc,x-16,y-20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+60;
								colorare(hdc,ps,c[crt->NE->culoare].R,c[crt->NE->culoare].G,c[crt->NE->culoare].B,x,y,x+15,y+15);
								root2=crt->NE;
								strcpy(v,root2->index);
								TextOut(hdc,x-16,y-20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+60;
								colorare(hdc,ps,c[crt->SW->culoare].R,c[crt->SW->culoare].G,c[crt->SW->culoare].B,x,y,x+15,y+15);
								root2=crt->SW;
								strcpy(v,root2->index);
								TextOut(hdc,x-16,y-20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+60;
								colorare(hdc,ps,c[crt->SE->culoare].R,c[crt->SE->culoare].G,c[crt->SE->culoare].B,x,y,x+15,y+15);
								root2=crt->SE;
								strcpy(v,root2->index);
								TextOut(hdc,x-16,y-20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
						x=x+20;
						}
						x=405;
						crt=prev->NE;
						if(crt->NW!=NULL)
						{
							colorare(hdc,ps,c[crt->NW->culoare].R,c[crt->NW->culoare].G,c[crt->NW->culoare].B,x,y,x+15,y+15);
								root2=crt->NW;
								strcpy(v,root2->index);
								TextOut(hdc,x-16,y-20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+60;
								colorare(hdc,ps,c[crt->NE->culoare].R,c[crt->NE->culoare].G,c[crt->NE->culoare].B,x,y,x+15,y+15);
								root2=crt->NE;
								strcpy(v,root2->index);
								TextOut(hdc,x-16,y-20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+60;
								colorare(hdc,ps,c[crt->SW->culoare].R,c[crt->SW->culoare].G,c[crt->SW->culoare].B,x,y,x+15,y+15);
								root2=crt->SW;
								strcpy(v,root2->index);
								TextOut(hdc,x-16,y-20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+60;
								colorare(hdc,ps,c[crt->SE->culoare].R,c[crt->SE->culoare].G,c[crt->SE->culoare].B,x,y,x+15,y+15);
								root2=crt->SE;
								strcpy(v,root2->index);
								TextOut(hdc,x-16,y-20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
								x=x+20;
						}
						x=710;
						crt=prev->SW;
						if(crt->NW!=NULL)
						{
							colorare(hdc,ps,c[crt->NW->culoare].R,c[crt->NW->culoare].G,c[crt->NW->culoare].B,x,y,x+15,y+15);
								root2=crt->NW;
								strcpy(v,root2->index);
								TextOut(hdc,x-16,y-20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+60;
								colorare(hdc,ps,c[crt->NE->culoare].R,c[crt->NE->culoare].G,c[crt->NE->culoare].B,x,y,x+15,y+15);
								root2=crt->NE;
								strcpy(v,root2->index);
								TextOut(hdc,x-16,y-20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+60;
								colorare(hdc,ps,c[crt->SW->culoare].R,c[crt->SW->culoare].G,c[crt->SW->culoare].B,x,y,x+15,y+15);
								root2=crt->SW;
								strcpy(v,root2->index);
								TextOut(hdc,x-16,y-20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+60;
								colorare(hdc,ps,c[crt->SE->culoare].R,c[crt->SE->culoare].G,c[crt->SE->culoare].B,x,y,x+15,y+15);
								root2=crt->SE;
								strcpy(v,root2->index);
								TextOut(hdc,x-16,y-20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
								x=x+20;

						}
						x=1015;
						crt=prev->SE;
						if(crt->NW!=NULL)
						{
							colorare(hdc,ps,c[crt->NW->culoare].R,c[crt->NW->culoare].G,c[crt->NW->culoare].B,x,y,x+15,y+15);
								root2=crt->NW;
								strcpy(v,root2->index);
								TextOut(hdc,x-16,y-20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+60;
								colorare(hdc,ps,c[crt->NE->culoare].R,c[crt->NE->culoare].G,c[crt->NE->culoare].B,x,y,x+15,y+15);
								root2=crt->NE;
								strcpy(v,root2->index);
								TextOut(hdc,x-16,y-20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+60;
								colorare(hdc,ps,c[crt->SW->culoare].R,c[crt->SW->culoare].G,c[crt->SW->culoare].B,x,y,x+15,y+15);
								root2=crt->SW;
								strcpy(v,root2->index);
								TextOut(hdc,x-16,y-20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+60;
								colorare(hdc,ps,c[crt->SE->culoare].R,c[crt->SE->culoare].G,c[crt->SE->culoare].B,x,y,x+15,y+15);
								root2=crt->SE;
								strcpy(v,root2->index);
								TextOut(hdc,x-16,y-20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
						}
						}
						int r,l;
				r=187;l=345;
				x=107;y=420;
				if(prev->NW!=NULL)
				{
				crt=prev->NW;
				for(int i=1;i<=4;i++)
				{
					if(crt->NW!=NULL)
					{
					for(int j=1;j<=4;j++)
					{
						MoveToEx(hdc,r,l,NULL);
				       LineTo(hdc,x,y);
					   if(j==4)
						   x=x+20;
					   else
					   x=x+60;
					}
					}
					if(i==1)
						{
							x=412;
							crt=prev->NE;
					    }
					if(i==2)
						{
							x=717;
							crt=prev->SW;
					    }
					   
					if(i==3)
						{
							x=1022;
							crt=prev->SE;
					    }
					r=r+300;
				}
				}
				nod *prev1=(nod*)malloc(sizeof(nod));
				if(prev!=NULL)
				prev1=prev;
				
				if(prev1->NW!=NULL)
				{
				x=6;y=550;
				prev=prev1->NW;
				if(prev->NW!=NULL)
				{
				crt=prev->NW;
				if(crt->NW!=NULL)
				{
					colorare(hdc,ps,c[crt->NW->culoare].R,c[crt->NW->culoare].G,c[crt->NW->culoare].B,x,y,x+15,y+15);
								root2=crt->NW;
								strcpy(v,root2->index);
								TextOut(hdc,x+3,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->NE->culoare].R,c[crt->NE->culoare].G,c[crt->NE->culoare].B,x,y,x+15,y+15);
								root2=crt->NE;
								strcpy(v,root2->index);
								TextOut(hdc,x+3,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SW->culoare].R,c[crt->SW->culoare].G,c[crt->SW->culoare].B,x,y,x+15,y+15);
								root2=crt->SW;
								strcpy(v,root2->index);
								TextOut(hdc,x+3,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SE->culoare].R,c[crt->SE->culoare].G,c[crt->SE->culoare].B,x,y,x+15,y+15);
								root2=crt->SE;
								strcpy(v,root2->index);
								TextOut(hdc,x+3,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
								x=13;
								for(int i=1;i<=4;i++)
					                       {
						                      MoveToEx(hdc,107,435,NULL);
				                                    LineTo(hdc,x,y);
					                                        x=x+16;
								           }
				}
							

				
				x=90;
				crt=prev->NE;
				if(crt->NW!=NULL)
				{
					colorare(hdc,ps,c[crt->NW->culoare].R,c[crt->NW->culoare].G,c[crt->NW->culoare].B,x,y,x+15,y+15);
								root2=crt->NW;
								strcpy(v,root2->index);
								TextOut(hdc,x+3,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->NE->culoare].R,c[crt->NE->culoare].G,c[crt->NE->culoare].B,x,y,x+15,y+15);
								root2=crt->NE;
								strcpy(v,root2->index);
								TextOut(hdc,x+3,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SW->culoare].R,c[crt->SW->culoare].G,c[crt->SW->culoare].B,x,y,x+15,y+15);
								root2=crt->SW;
								strcpy(v,root2->index);
								TextOut(hdc,x+3,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SE->culoare].R,c[crt->SE->culoare].G,c[crt->SE->culoare].B,x,y,x+15,y+15);
								root2=crt->SE;
								strcpy(v,root2->index);
								TextOut(hdc,x+3,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
								x=97;
								for(int i=1;i<=4;i++)
					                       {
						                      MoveToEx(hdc,167,435,NULL);
				                                    LineTo(hdc,x,y);
					                                        x=x+16;
								           }
				}
				x=164;
				crt=prev->SW;
				if(crt->NW!=NULL)
				{
					colorare(hdc,ps,c[crt->NW->culoare].R,c[crt->NW->culoare].G,c[crt->NW->culoare].B,x,y,x+15,y+15);
								root2=crt->NW;
								strcpy(v,root2->index);
								TextOut(hdc,x+3,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->NE->culoare].R,c[crt->NE->culoare].G,c[crt->NE->culoare].B,x,y,x+15,y+15);
								root2=crt->NE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SW->culoare].R,c[crt->SW->culoare].G,c[crt->SW->culoare].B,x,y,x+15,y+15);
								root2=crt->SW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SE->culoare].R,c[crt->SE->culoare].G,c[crt->SE->culoare].B,x,y,x+15,y+15);
								root2=crt->SE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
								x=171;
								for(int i=1;i<=4;i++)
					                       {
						                      MoveToEx(hdc,227,435,NULL);
				                                    LineTo(hdc,x,y);
					                                        x=x+16;
								           }
				}
				x=238;
				crt=prev->SE;
				if(crt->NW!=NULL)
				{
					colorare(hdc,ps,c[crt->NW->culoare].R,c[crt->NW->culoare].G,c[crt->NW->culoare].B,x,y,x+15,y+15);
								root2=crt->NW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->NE->culoare].R,c[crt->NE->culoare].G,c[crt->NE->culoare].B,x,y,x+15,y+15);
								root2=crt->NE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SW->culoare].R,c[crt->SW->culoare].G,c[crt->SW->culoare].B,x,y,x+15,y+15);
								root2=crt->SW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SE->culoare].R,c[crt->SE->culoare].G,c[crt->SE->culoare].B,x,y,x+15,y+15);
								root2=crt->SE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
								x=245;
								for(int i=1;i<=4;i++)
					                       {
						                      MoveToEx(hdc,287,435,NULL);
				                                    LineTo(hdc,x,y);
					                                        x=x+16;
								           }
				}
				}


				//////////
				prev=prev1->NE;
				if(prev->NW!=NULL)
				{
				crt=prev->NW;
				x=319;y=550;
				if(crt->NW!=NULL)
				{
					colorare(hdc,ps,c[crt->NW->culoare].R,c[crt->NW->culoare].G,c[crt->NW->culoare].B,x,y,x+15,y+15);
								root2=crt->NW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->NE->culoare].R,c[crt->NE->culoare].G,c[crt->NE->culoare].B,x,y,x+15,y+15);
								root2=crt->NE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SW->culoare].R,c[crt->SW->culoare].G,c[crt->SW->culoare].B,x,y,x+15,y+15);
								root2=crt->SW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SE->culoare].R,c[crt->SE->culoare].G,c[crt->SE->culoare].B,x,y,x+15,y+15);
								root2=crt->SE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
								x=326;
								for(int i=1;i<=4;i++)
					                       {
						                      MoveToEx(hdc,411,435,NULL);
				                                    LineTo(hdc,x,y);
					                                        x=x+16;
								           }
				}
							

				
				x=403;
				crt=prev->NE;
				if(crt->NW!=NULL)
				{
					colorare(hdc,ps,c[crt->NW->culoare].R,c[crt->NW->culoare].G,c[crt->NW->culoare].B,x,y,x+15,y+15);
								root2=crt->NW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->NE->culoare].R,c[crt->NE->culoare].G,c[crt->NE->culoare].B,x,y,x+15,y+15);
								root2=crt->NE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SW->culoare].R,c[crt->SW->culoare].G,c[crt->SW->culoare].B,x,y,x+15,y+15);
								root2=crt->SW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SE->culoare].R,c[crt->SE->culoare].G,c[crt->SE->culoare].B,x,y,x+15,y+15);
								root2=crt->SE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
								x=410;
								for(int i=1;i<=4;i++)
					                       {
						                      MoveToEx(hdc,471,435,NULL);
				                                    LineTo(hdc,x,y);
					                                        x=x+16;
								           }
				}
				x=477;
				crt=prev->SW;
				if(crt->NW!=NULL)
				{
					colorare(hdc,ps,c[crt->NW->culoare].R,c[crt->NW->culoare].G,c[crt->NW->culoare].B,x,y,x+15,y+15);
								root2=crt->NW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->NE->culoare].R,c[crt->NE->culoare].G,c[crt->NE->culoare].B,x,y,x+15,y+15);
								root2=crt->NE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SW->culoare].R,c[crt->SW->culoare].G,c[crt->SW->culoare].B,x,y,x+15,y+15);
								root2=crt->SW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SE->culoare].R,c[crt->SE->culoare].G,c[crt->SE->culoare].B,x,y,x+15,y+15);
								root2=crt->SE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
								x=484;
								for(int i=1;i<=4;i++)
					                       {
						                      MoveToEx(hdc,532,435,NULL);
				                                    LineTo(hdc,x,y);
					                                        x=x+16;
								           }
				}
				x=561;
				crt=prev->SE;
				if(crt->NW!=NULL)
				{
					colorare(hdc,ps,c[crt->NW->culoare].R,c[crt->NW->culoare].G,c[crt->NW->culoare].B,x,y,x+15,y+15);
								root2=crt->NW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->NE->culoare].R,c[crt->NE->culoare].G,c[crt->NE->culoare].B,x,y,x+15,y+15);
								root2=crt->NE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SW->culoare].R,c[crt->SW->culoare].G,c[crt->SW->culoare].B,x,y,x+15,y+15);
								root2=crt->SW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SE->culoare].R,c[crt->SE->culoare].G,c[crt->SE->culoare].B,x,y,x+15,y+15);
								root2=crt->SE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
								x=568;
								for(int i=1;i<=4;i++)
					                       {
						                      MoveToEx(hdc,592,435,NULL);
				                                    LineTo(hdc,x,y);
					                                        x=x+16;
								}	      
				}
				
				}
				
				//////////
				prev=prev1->SW;
				
				if(prev->NW!=NULL)
				{
					crt=prev->NW;
				x=700;y=550;
				if(crt->NW!=NULL)
				{
					colorare(hdc,ps,c[crt->NW->culoare].R,c[crt->NW->culoare].G,c[crt->NW->culoare].B,x,y,x+15,y+15);
								root2=crt->NW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->NE->culoare].R,c[crt->NE->culoare].G,c[crt->NE->culoare].B,x,y,x+15,y+15);
								root2=crt->NE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SW->culoare].R,c[crt->SW->culoare].G,c[crt->SW->culoare].B,x,y,x+15,y+15);
								root2=crt->SW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SE->culoare].R,c[crt->SE->culoare].G,c[crt->SE->culoare].B,x,y,x+15,y+15);
								root2=crt->SE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
								x=707;
								for(int i=1;i<=4;i++)
					                       {
						                      MoveToEx(hdc,717,435,NULL);
				                                    LineTo(hdc,x,y);
					                                        x=x+16;
								           }
				}
							

				
				x=774;
				crt=prev->NE;
				if(crt->NW!=NULL)
				{
					colorare(hdc,ps,c[crt->NW->culoare].R,c[crt->NW->culoare].G,c[crt->NW->culoare].B,x,y,x+15,y+15);
								root2=crt->NW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->NE->culoare].R,c[crt->NE->culoare].G,c[crt->NE->culoare].B,x,y,x+15,y+15);
								root2=crt->NE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SW->culoare].R,c[crt->SW->culoare].G,c[crt->SW->culoare].B,x,y,x+15,y+15);
								root2=crt->SW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SE->culoare].R,c[crt->SE->culoare].G,c[crt->SE->culoare].B,x,y,x+15,y+15);
								root2=crt->SE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
								x=781;
								for(int i=1;i<=4;i++)
					                       {
						                      MoveToEx(hdc,774,435,NULL);
				                                    LineTo(hdc,x,y);
					                                        x=x+16;
								           }
				}
				x=858;
				crt=prev->SW;
				if(crt->NW!=NULL)
				{
					colorare(hdc,ps,c[crt->NW->culoare].R,c[crt->NW->culoare].G,c[crt->NW->culoare].B,x,y,x+15,y+15);
								root2=crt->NW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->NE->culoare].R,c[crt->NE->culoare].G,c[crt->NE->culoare].B,x,y,x+15,y+15);
								root2=crt->NE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SW->culoare].R,c[crt->SW->culoare].G,c[crt->SW->culoare].B,x,y,x+15,y+15);
								root2=crt->SW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SE->culoare].R,c[crt->SE->culoare].G,c[crt->SE->culoare].B,x,y,x+15,y+15);
								root2=crt->SE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
								x=865;
								for(int i=1;i<=4;i++)
					                       {
						                      MoveToEx(hdc,837,435,NULL);
				                                    LineTo(hdc,x,y);
					                                        x=x+16;
								           }
				}
				x=932;
				crt=prev->SE;
				if(crt->NW!=NULL)
				{
					colorare(hdc,ps,c[crt->NW->culoare].R,c[crt->NW->culoare].G,c[crt->NW->culoare].B,x,y,x+15,y+15);
								root2=crt->NW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->NE->culoare].R,c[crt->NE->culoare].G,c[crt->NE->culoare].B,x,y,x+15,y+15);
								root2=crt->NE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SW->culoare].R,c[crt->SW->culoare].G,c[crt->SW->culoare].B,x,y,x+15,y+15);
								root2=crt->SW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SE->culoare].R,c[crt->SE->culoare].G,c[crt->SE->culoare].B,x,y,x+15,y+15);
								root2=crt->SE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
								x=939;
								for(int i=1;i<=4;i++)
					                       {
						                      MoveToEx(hdc,896,435,NULL);
				                                    LineTo(hdc,x,y);
					                                        x=x+16;
								           }
				}
				}
				
				//////
				prev=prev1->SE;
				if(prev->NW!=NULL)
				{
				crt=prev->NW;
				x=1025;y=550;
				if(crt->NW!=NULL)
				{
					colorare(hdc,ps,c[crt->NW->culoare].R,c[crt->NW->culoare].G,c[crt->NW->culoare].B,x,y,x+15,y+15);
								root2=crt->NW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->NE->culoare].R,c[crt->NE->culoare].G,c[crt->NE->culoare].B,x,y,x+15,y+15);
								root2=crt->NE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SW->culoare].R,c[crt->SW->culoare].G,c[crt->SW->culoare].B,x,y,x+15,y+15);
								root2=crt->SW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SE->culoare].R,c[crt->SE->culoare].G,c[crt->SE->culoare].B,x,y,x+15,y+15);
								root2=crt->SE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
								x=1032;
								for(int i=1;i<=4;i++)
					                       {
						                      MoveToEx(hdc,1022,435,NULL);
				                                    LineTo(hdc,x,y);
					                                        x=x+16;
								           }
				}
							

				
				x=1099;
				crt=prev->NE;
				if(crt->NW!=NULL)
				{
					colorare(hdc,ps,c[crt->NW->culoare].R,c[crt->NW->culoare].G,c[crt->NW->culoare].B,x,y,x+15,y+15);
								root2=crt->NW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->NE->culoare].R,c[crt->NE->culoare].G,c[crt->NE->culoare].B,x,y,x+15,y+15);
								root2=crt->NE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SW->culoare].R,c[crt->SW->culoare].G,c[crt->SW->culoare].B,x,y,x+15,y+15);
								root2=crt->SW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SE->culoare].R,c[crt->SE->culoare].G,c[crt->SE->culoare].B,x,y,x+15,y+15);
								root2=crt->SE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
								x=1106;
								for(int i=1;i<=4;i++)
					                       {
						                      MoveToEx(hdc,1082,435,NULL);
				                                    LineTo(hdc,x,y);
					                                        x=x+16;
								           }
				}
				x=1173;
				crt=prev->SW;
				if(crt->NW!=NULL)
				{
					colorare(hdc,ps,c[crt->NW->culoare].R,c[crt->NW->culoare].G,c[crt->NW->culoare].B,x,y,x+15,y+15);
								root2=crt->NW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->NE->culoare].R,c[crt->NE->culoare].G,c[crt->NE->culoare].B,x,y,x+15,y+15);
								root2=crt->NE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SW->culoare].R,c[crt->SW->culoare].G,c[crt->SW->culoare].B,x,y,x+15,y+15);
								root2=crt->SW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SE->culoare].R,c[crt->SE->culoare].G,c[crt->SE->culoare].B,x,y,x+15,y+15);
								root2=crt->SE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
								x=1180;
								for(int i=1;i<=4;i++)
					                       {
						                      MoveToEx(hdc,1142,435,NULL);
				                                    LineTo(hdc,x,y);
					                                        x=x+16;
								           }
				}
				x=1250;
				crt=prev->SE;
				if(crt->NW!=NULL)
				{
					colorare(hdc,ps,c[crt->NW->culoare].R,c[crt->NW->culoare].G,c[crt->NW->culoare].B,x,y,x+15,y+15);
								root2=crt->NW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->NE->culoare].R,c[crt->NE->culoare].G,c[crt->NE->culoare].B,x,y,x+15,y+15);
								root2=crt->NE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SW->culoare].R,c[crt->SW->culoare].G,c[crt->SW->culoare].B,x,y,x+15,y+15);
								root2=crt->SW;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
					            x=x+16;
								colorare(hdc,ps,c[crt->SE->culoare].R,c[crt->SE->culoare].G,c[crt->SE->culoare].B,x,y,x+15,y+15);
								root2=crt->SE;
								strcpy(v,root2->index);
								TextOut(hdc,x-1,y+20,v,strlen(v));
								SetTextColor(hdc,RGB(0,0,255));
								x=1257;
								for(int i=1;i<=4;i++)
					                       {
						                      MoveToEx(hdc,1202,435,NULL);
				                                    LineTo(hdc,x,y);
					                                        x=x+16;
								           }
				}




						}
						}
						ok=0;
		}

		 

		EndPaint(hWnd2, &ps);
		//UpdateWindow(hWnd2);
					  }
		break;
		default://InvalidateRect(hWnd2,NULL,FALSE);
		return DefWindowProc(hWnd2, message, wParam, lParam);
	}
	return 0;
}

// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	UNREFERENCED_PARAMETER(lParam);
	switch (message)
	{
	case WM_INITDIALOG:
		return (INT_PTR)TRUE;

	case WM_COMMAND:
		if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
		{
			EndDialog(hDlg, LOWORD(wParam));
			return (INT_PTR)TRUE;
		}
		break;
	}
	return (INT_PTR)FALSE;
}